#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#include "../src/distribution.c"
#include "../src/qfunc.c"

typedef struct _LogPRatingTestDatum LogPRatingTestDatum ;
struct _LogPRatingTestDatum 
{ 
  struct
    {
      unsigned int     rating;
      float            alpha[4];
      float            logbeta;
    }                                   inputs;
  float                                desired_output;
};

static void
test_logprating (void)
{
  LogPRatingTestDatum data[] = 
    {{{3, {0.833249, 0.965062, 0.0882295, 0.148109}, 0.254743}, -1.04452}, {{2, {0.695449, 0.488398, 0.97021, 0.32168}, 0.664682}, -2.17304}, {{1, {0.228919, 0.708024, 0.889281, 0.512718}, 0.0933638}, -1.55832}, {{0, {0.138158, 0.925201, 0.375761, 0.949392}, 0.257005}, -0.894948}, {{0, {0.958452, 0.437078, 0.964528, 0.0474854}, 0.125202}, -1.88809}, {{3, {0.472016, 0.876298, 0.899376, 0.870459}, 0.776567}, -1.66853}, {{1, {0.387901, 0.929165, 0.54878, 0.111885}, 0.158982}, -1.95372}, {{1, {0.221142, 0.659499, 0.599167, 0.0656183}, 0.0829836}, -1.71996}, {{2, {0.734297, 0.223406, 0.116226, 0.825978}, 0.775846}, -0.81863}, {{2, {0.786328, 0.151698, 0.778493, 0.650643}, 0.314312}, -1.71195}};

  for (unsigned int i = 0; i < sizeof (data) / sizeof (data[0]); ++i)
    {
      float dlogbeta;
      float ddlogbeta;

#define alphafunc(x) data[i].inputs.alpha[x]
      float output = logprating (data[i].inputs.rating,
                                 alphafunc,
                                 data[i].inputs.logbeta,
                                 dlogbeta,
                                 ddlogbeta,
                                 4);
#undef alphafunc

      assert (fabs (output - data[i].desired_output) <=
              1e-3 * (1 + fabs (output) + fabs (data[i].desired_output)) ||
              (fprintf (stderr, "%g ?= %g\n", output, data[i].desired_output),
               0));
    }
}

typedef struct _NormalDistributionTestDatum NormalDistributionTestDatum;
struct _NormalDistributionTestDatum 
{
  float mean;
  float stddev;
  float x;
  float desired_output;
  float desired_doutput;
};

static void
test_normaldistribution (void)
{
  NormalDistributionTestDatum data[] = 
    {{0.926397, 0.301751, 0.58779, -0.350384, 3.71875}, {0.473612, 0.156177, 0.0456262, -2.81705, 17.5467}, {0.784299, 0.208136, 0.79302, 0.649749, -0.201327}, {0.0686202, 0.731358, 0.50866, -0.787093, -0.822682}, {0.847739, 0.199902, 0.073739, -6.80483, 19.369}, {0.227435, 0.700526, 0.13108, -0.572474, 0.196347}, {0.752228, 0.423733, 0.555054, -0.168552, 1.09816}, {0.456649, 0.623583, 0.788376, -0.588161, -0.853083}, {0.628656, 0.154897, 0.0357929, -6.37867, 24.7096}, {0.314764, 0.47248, 0.109271, -0.263757, 0.920512}};

  for (unsigned int i = 0; i < sizeof (data) / sizeof (data[0]); ++i)
    {
      NormalDistribution p = normal_distribution (data[i].mean, data[i].stddev);

      float output = p.base.logpdf (data[i].x, &p.base);
      float doutput = p.base.dlogpdf (data[i].x, &p.base);

      assert (fabs (output - data[i].desired_output) <=
              1e-3 * (1 + fabs (output) + fabs (data[i].desired_output)) ||
              (fprintf (stderr, "%g ?= %g\n", output, data[i].desired_output),
               0));

      assert (fabs (doutput - data[i].desired_doutput) <=
              1e-3 * (1 + fabs (doutput) + fabs (data[i].desired_doutput)) ||
              (fprintf (stderr, "%g ?= %g\n", doutput, data[i].desired_doutput),
               0));
    }
}
        

typedef struct _QFuncTestDatum QFuncTestDatum ;
struct _QFuncTestDatum 
{ 
  struct
    {
      float    alpha[4 * 5 * 5];
      float    logbeta;
      float    gamma[5 * 5];
      float    pz[5];
      float    priorz[5];
      Rating    ratings[8];
      float    alphastddev;
      float    logbetamean;
      float    logbetastddev;
      float    gammamean;
      float    gammastddev;
    }                   inputs;
  struct
    {
      float q;
      float dqdlogbeta;
      float ddqddlogbeta;
    }                   desired_output;
};

static void
test_qfunc (void)
{
  QFuncTestDatum data[] = 
    {{{{-1., 0.330849, 0.507326, 0.417076, 0.748554, 0.795991, -1.,  0.360986, 0.420797, 0.492968, 0.343556, 0.234987, -1., 0.965884,  0.997836, 0.448936, 0.196478, 0.778474, -1., 0.0330242, 0.84882,  0.0408982, 0.984339, 0.343404, -1., -1., 0.189495, 0.518646,  0.556804, 0.309766, 0.858645, -1., 0.0113192, 0.139728, 0.561213,  0.0626543, 0.650333, -1., 0.718931, 0.0682445, 0.719098, 0.415347,  0.753047, -1., 0.0704085, 0.270162, 0.218869, 0.974572,  0.0373843, -1., -1., 0.421342, 0.177971, 0.990234, 0.69398,  0.231847, -1., 0.659325, 0.433429, 0.384214, 0.373202,  0.648006, -1., 0.293701, 0.823001, 0.310547, 0.997673,  0.574769, -1., 0.754757, 0.591449, 0.582326, 0.821723,  0.684348, -1., -1., 0.321288, 0.363457, 0.84715, 0.646964,  0.899946, -1., 0.185486, 0.856917, 0.952984, 0.668099,  0.526161, -1., 0.423488, 0.56877, 0.294897, 0.878155,  0.129787, -1., 0.745768, 0.98435, 0.880482, 0.555018,  0.991011, -1.},  0.392901, {1., 0.298156, 0.733295, 0.306663, 0.0716129, 0.934699,  1., 0.886145, 0.659699, 0.171667, 0.749213, 0.0292279, 1.,  0.706715, 0.503568, 0.223051, 0.60574, 0.137946, 1., 0.208671,  0.344896, 0.475953, 0.392177, 0.22432, 1.}, {0.464414, 0.920935,  0.401166, 0.83142, 0.166257}, {0.18764, 0.0945031, 0.759807,  0.231558,  0.301495}, {{0, 4}, {1, 1}, {0, 4}, {1, 2}, {2, 4}, {2, 1}, {1,  0}, {1, 2}}, 0.434804, 0.58814, 0.482345, 0.272267,  0.728089}, {-50.0283, -26.4562, -52.7106}}, {{{-1., 0.0845719,  0.259294, 0.666527, 0.590143, 0.875901, -1., 0.914398, 0.190574,  0.197966, 0.651581, 0.449984, -1., 0.269639, 0.796799, 0.820161,  0.283727, 0.0819994, -1., 0.702296, 0.060354, 0.0521684, 0.780504,  0.267492, -1., -1., 0.472214, 0.569823, 0.508237, 0.539403,  0.387642, -1., 0.310529, 0.841709, 0.94926, 0.511741,  0.396131, -1., 0.651135, 0.751295, 0.86016, 0.946147,  0.381496, -1., 0.954496, 0.0399993, 0.662421, 0.299496,  0.252199, -1., -1., 0.979645, 0.610252, 0.518992, 0.984707,  0.507431, -1., 0.0404294, 0.0107554, 0.445304, 0.119789,  0.7299, -1., 0.169046, 0.496043, 0.608048, 0.333769,  0.517911, -1., 0.744748, 0.747888, 0.387622, 0.136416,  0.790253, -1., -1., 0.707888, 0.725201, 0.836919, 0.538053,  0.728243, -1., 0.114949, 0.317927, 0.553346, 0.220812,  0.0745192, -1., 0.307172, 0.108043, 0.101023, 0.344619,  0.138126, -1., 0.612, 0.492975, 0.0108497, 0.620215,  0.867252, -1.},  0.745088, {1., 0.623228, 0.483799, 0.0769989, 0.0371991, 0.898027,  1., 0.64688, 0.538945, 0.308956, 0.783078, 0.328952, 1., 0.985599,  0.0881438, 0.708559, 0.0217805, 0.877556, 1., 0.987121, 0.36394,  0.883655, 0.265556, 0.494145, 1.}, {0.35309, 0.26344, 0.398305,  0.749058, 0.729863}, {0.779641, 0.321306, 0.711859, 0.831836,  0.132762}, {{2, 2}, {1, 1}, {1, 2}, {2, 1}, {1, 3}, {1, 3}, {2,  2}, {3, 3}}, 0.78236, 0.402903, 0.0487576, 0.803809,  0.796761}, {-74.3867, -184.755, -484.568}}, {{{-1., 0.314759,  0.340199, 0.782029, 0.919205, 0.327638, -1., 0.976259, 0.898374,  0.653649, 0.833493, 0.623168, -1., 0.634934, 0.255344, 0.0844351,  0.893306, 0.855292, -1., 0.934038, 0.372576, 0.06147, 0.722531,  0.151678, -1., -1., 0.969673, 0.0127124, 0.918722, 0.354917,  0.654914, -1., 0.672514, 0.136693, 0.435712, 0.327276,  0.696255, -1., 0.238319, 0.782063, 0.493783, 0.0730867,  0.603385, -1., 0.526719, 0.409348, 0.179781, 0.748093,  0.592681, -1., -1., 0.0367715, 0.118311, 0.0255621, 0.441003,  0.0670982, -1., 0.105599, 0.106841, 0.086086, 0.412184,  0.433085, -1., 0.970148, 0.650375, 0.0849083, 0.73683,  0.731828, -1., 0.868312, 0.591126, 0.663743, 0.128443,  0.341593, -1., -1., 0.181778, 0.483962, 0.38035, 0.748912,  0.145006, -1., 0.365651, 0.354788, 0.30791, 0.0779082,  0.260053, -1., 0.247947, 0.221824, 0.665724, 0.826968,  0.2778, -1., 0.571449, 0.580816, 0.0901375, 0.545971,  0.703137, -1.},  0.98969, {1., 0.426394, 0.417528, 0.361544, 0.807913, 0.942432, 1.,  0.0371782, 0.612632, 0.662906, 0.57678, 0.68239, 1., 0.304722,  0.584998, 0.316728, 0.434443, 0.0828989, 1., 0.919274, 0.48976,  0.156643, 0.51145, 0.338458, 1.}, {0.399623, 0.610671, 0.808312,  0.348768, 0.973228}, {0.193143, 0.446768, 0.540855, 0.0307967,  0.155965}, {{2, 4}, {1, 0}, {2, 3}, {2, 3}, {3, 2}, {2, 3}, {1,  3}, {3, 4}}, 0.834136, 0.877949, 0.454016, 0.473575,  0.529413}, {-81.1382, -71.6756, -102.387}}, {{{-1., 0.292951,  0.137288, 0.0391319, 0.446514, 0.373677, -1., 0.647528, 0.882489,  0.935065, 0.0352188, 0.247906, -1., 0.271818, 0.126752, 0.686451,  0.274677, 0.0786744, -1., 0.679984, 0.145596, 0.243881, 0.92271,  0.845849, -1., -1., 0.267647, 0.789864, 0.449135, 0.316435,  0.974697, -1., 0.652576, 0.410003, 0.869921, 0.60102,  0.00504765, -1., 0.527514, 0.934856, 0.565801, 0.757142,  0.255696, -1., 0.808104, 0.87935, 0.482465, 0.177022,  0.12812, -1., -1., 0.733754, 0.238584, 0.254313, 0.282271,  0.466106, -1., 0.44872, 0.805178, 0.965836, 0.49141,  0.796144, -1., 0.395175, 0.0959149, 0.890389, 0.791096,  0.867661, -1., 0.161059, 0.324588, 0.0339543, 0.611964,  0.352955, -1., -1., 0.445238, 0.55149, 0.434942, 0.224835,  0.711484, -1., 0.312905, 0.18063, 0.942564, 0.245378,  0.864185, -1., 0.375452, 0.976728, 0.753968, 0.0680414,  0.980277, -1., 0.880814, 0.863579, 0.276945, 0.112617,  0.719755, -1.},  0.538991, {1., 0.242991, 0.500652, 0.3668, 0.0937527, 0.691501, 1.,  0.0657101, 0.141965, 0.382268, 0.378596, 0.88508, 1., 0.199401,  0.13689, 0.514411, 0.509628, 0.222673, 1., 0.382922, 0.446369,  0.529351, 0.341859, 0.519343, 1.}, {0.169424, 0.416734, 0.622104,  0.980352, 0.926433}, {0.916082, 0.255304, 0.886599, 0.234932,  0.850372}, {{1, 1}, {1, 1}, {0, 3}, {0, 3}, {3, 2}, {1, 2}, {1,  1}, {2, 2}}, 0.113339, 0.504331, 0.856336, 0.965292,  0.913938}, {-58.3546, -36.6777, -65.3029}}, {{{-1., 0.367441,  0.341925, 0.455663, 0.691266, 0.984519, -1., 0.895556, 0.926312,  0.349407, 0.465176, 0.726132, -1., 0.509578, 0.727302, 0.484824,  0.799699, 0.593496, -1., 0.471998, 0.598224, 0.564767, 0.743124,  0.358659, -1., -1., 0.0938933, 0.708431, 0.777833, 0.444721,  0.726453, -1., 0.366505, 0.322169, 0.753456, 0.741934,  0.470949, -1., 0.395857, 0.404049, 0.276758, 0.744817,  0.886279, -1., 0.676747, 0.791934, 0.945118, 0.292783,  0.204749, -1., -1., 0.19371, 0.380351, 0.549659, 0.846089,  0.0998164, -1., 0.67192, 0.771826, 0.401368, 0.373364,  0.305415, -1., 0.449657, 0.647912, 0.63143, 0.834466,  0.0538001, -1., 0.243863, 0.354672, 0.0896487, 0.167521,  0.567116, -1., -1., 0.562738, 0.144531, 0.874738, 0.362367,  0.369028, -1., 0.76418, 0.325079, 0.516278, 0.269212,  0.0922594, -1., 0.553253, 0.11491, 0.895848, 0.786845,  0.103596, -1., 0.466998, 0.264418, 0.952379, 0.0497957,  0.223136, -1.},  0.909746, {1., 0.86273, 0.882275, 0.65602, 0.347008, 0.718199, 1.,  0.00753644, 0.293653, 0.97798, 0.95402, 0.682457, 1., 0.777375,  0.708768, 0.86176, 0.129204, 0.662465, 1., 0.81292, 0.0749159,  0.0256086, 0.195466, 0.548502, 1.}, {0.122537, 0.975813, 0.97233,  0.638755, 0.259807}, {0.0935384, 0.31631, 0.291747, 0.541607,  0.086002}, {{0, 0}, {2, 1}, {0, 4}, {2, 4}, {3, 2}, {1, 2}, {3,  0}, {3, 0}}, 0.0226573, 0.313767, 0.587588, 0.403545,  0.245282}, {-76.7565, -67.6508, -94.4495}}, {{{-1., 0.604999,  0.725827, 0.27434, 0.582818, 0.792079, -1., 0.650911, 0.248732,  0.387351, 0.243578, 0.528374, -1., 0.272919, 0.415021, 0.604823,  0.268567, 0.17938, -1., 0.0987104, 0.313075, 0.72696, 0.0933783,  0.0760531, -1., -1., 0.999308, 0.139372, 0.689834, 0.830771,  0.394309, -1., 0.413545, 0.415493, 0.247953, 0.602229,  0.762634, -1., 0.166761, 0.860602, 0.358651, 0.23426,  0.893843, -1., 0.445581, 0.753829, 0.965693, 0.714462,  0.346871, -1., -1., 0.440754, 0.238733, 0.621084, 0.270818,  0.441445, -1., 0.0993603, 0.931251, 0.440047, 0.0471366,  0.685815, -1., 0.515757, 0.192094, 0.444907, 0.923181,  0.348996, -1., 0.331492, 0.0862558, 0.688921, 0.455153,  0.88591, -1., -1., 0.332427, 0.723229, 0.740691, 0.53904,  0.891673, -1., 0.484496, 0.119607, 0.268222, 0.450228,  0.385136, -1., 0.188356, 0.828175, 0.403091, 0.699321,  0.672599, -1., 0.636082, 0.958184, 0.77614, 0.323603,  0.30459, -1.},  0.871928, {1., 0.0872185, 0.86845, 0.41868, 0.539502, 0.36399, 1.,  0.127759, 0.87964, 0.647828, 0.879494, 0.00815262, 1., 0.611418,  0.1976, 0.494358, 0.819797, 0.783243, 1., 0.794509, 0.795038,  0.147198, 0.147161, 0.836325, 1.}, {0.0188982, 0.823595, 0.84257,  0.964396, 0.93168}, {0.955145, 0.423891, 0.424895, 0.56769,  0.827386}, {{3, 1}, {0, 2}, {2, 3}, {0, 2}, {1, 3}, {2, 4}, {3,  2}, {1, 0}}, 0.544251, 0.777066, 0.688196, 0.819233,  0.932833}, {-82.0568, -67.2593, -101.462}}, {{{-1., 0.579466,  0.193837, 0.999437, 0.14959, 0.784957, -1., 0.3988, 0.852239,  0.0024294, 0.948633, 0.379901, -1., 0.0286439, 0.159859, 0.984237,  0.448222, 0.0734988, -1., 0.735968, 0.559342, 0.880532, 0.246113,  0.191718, -1., -1., 0.782276, 0.192336, 0.426879, 0.258885,  0.202809, -1., 0.998499, 0.427443, 0.109295, 0.417852,  0.599699, -1., 0.575204, 0.106866, 0.469219, 0.219798,  0.54656, -1., 0.947007, 0.484982, 0.771576, 0.473061,  0.211038, -1., -1., 0.92564, 0.891044, 0.226948, 0.0193205,  0.143365, -1., 0.698708, 0.800069, 0.760435, 0.940555,  0.700209, -1., 0.372626, 0.65114, 0.522703, 0.10051,  0.797422, -1., 0.544274, 0.053484, 0.880712, 0.250863,  0.597267, -1., -1., 0.568502, 0.109135, 0.777802, 0.386229,  0.642861, -1., 0.218091, 0.550853, 0.366909, 0.499497,  0.519383, -1., 0.750785, 0.606473, 0.558941, 0.819173,  0.378158, -1., 0.955333, 0.0362381, 0.718664, 0.580736,  0.411059, -1.},  0.982754, {1., 0.837952, 0.329873, 0.813791, 0.414253, 0.728817,  1., 0.552072, 0.427562, 0.771391, 0.510726, 0.00121816, 1.,  0.0606538, 0.271895, 0.991344, 0.250434, 0.454181, 1., 0.712953,  0.17217, 0.872275, 0.498847, 0.676715, 1.}, {0.453507, 0.291539,  0.0877885, 0.693961, 0.615554}, {0.961666, 0.273997, 0.279709,  0.886737,  0.409595}, {{3, 0}, {1, 1}, {0, 2}, {3, 2}, {1, 1}, {3, 2}, {2,  1}, {2, 3}}, 0.846435, 0.508317, 0.376011, 0.408377,  0.785781}, {-57.6002, -55.0533, -75.8507}}, {{{-1., 0.236423,  0.384667, 0.157943, 0.3316, 0.523469, -1., 0.212497, 0.285668,  0.832753, 0.846754, 0.75899, -1., 0.994128, 0.744965, 0.152793,  0.143436, 0.032462, -1., 0.470967, 0.873084, 0.256698, 0.622867,  0.624533, -1., -1., 0.364766, 0.880687, 0.214491, 0.838752,  0.128344, -1., 0.49602, 0.0565477, 0.507151, 0.604874,  0.283523, -1., 0.77088, 0.674398, 0.758121, 0.524533,  0.776752, -1., 0.929433, 0.605328, 0.381098, 0.74429,  0.458466, -1., -1., 0.732244, 0.1244, 0.121423, 0.833934,  0.367478, -1., 0.243712, 0.906932, 0.995182, 0.239134,  0.747692, -1., 0.850384, 0.488031, 0.63426, 0.464169,  0.0795042, -1., 0.813633, 0.87614, 0.939635, 0.302752,  0.8842, -1., -1., 0.270812, 0.558537, 0.558462, 0.425733,  0.538567, -1., 0.434138, 0.43704, 0.5918, 0.171089, 0.190425, -1.,  0.530108, 0.596618, 0.931955, 0.442733, 0.679723, -1., 0.108587,  0.297695, 0.978564, 0.600219, 0.294954, -1.},  0.421555, {1., 0.0389286, 0.297467, 0.410754, 0.150744, 0.480391,  1., 0.739004, 0.985021, 0.612176, 0.0462534, 0.301965, 1.,  0.393221, 0.441087, 0.855828, 0.771857, 0.796603, 1., 0.509132,  0.413095, 0.0921334, 0.688016, 0.211437, 1.}, {0.434531, 0.491914,  0.393062, 0.789882, 0.395603}, {0.194447, 0.982308, 0.639139,  0.915211,  0.455443}, {{1, 4}, {3, 2}, {2, 4}, {3, 2}, {1, 4}, {3, 1}, {3,  3}, {1, 2}}, 0.997287, 0.0269625, 0.868958, 0.153478,  0.604066}, {-47.3877, -28.8214, -50.4519}}, {{{-1., 0.585876,  0.01313, 0.381621, 0.807463, 0.0767434, -1., 0.600035, 0.289488,  0.119447, 0.865306, 0.165504, -1., 0.797574, 0.726385, 0.0754237,  0.769901, 0.603126, -1., 0.744077, 0.436285, 0.85469, 0.147684,  0.74679, -1., -1., 0.409322, 0.985732, 0.994206, 0.142723,  0.823447, -1., 0.972602, 0.612584, 0.33526, 0.746704,  0.372567, -1., 0.323097, 0.215813, 0.881398, 0.207063,  0.525523, -1., 0.489428, 0.805974, 0.437162, 0.922397,  0.745352, -1., -1., 0.369689, 0.582472, 0.774713, 0.998562,  0.960366, -1., 0.596741, 0.780508, 0.855839, 0.136919,  0.624139, -1., 0.167923, 0.520579, 0.390216, 0.251573,  0.844826, -1., 0.304766, 0.508818, 0.0445096, 0.319303,  0.815337, -1., -1., 0.702844, 0.607348, 0.396906, 0.0699855,  0.333156, -1., 0.0248754, 0.622193, 0.0714233, 0.372789,  0.428135, -1., 0.841686, 0.215584, 0.23587, 0.803995,  0.673763, -1., 0.695006, 0.845654, 0.552423, 0.828936,  0.39024, -1.},  0.336835, {1., 0.507913, 0.509633, 0.574903, 0.633991, 0.900566,  1., 0.112727, 0.504917, 0.300835, 0.87569, 0.490533, 1., 0.433494,  0.928046, 0.447556, 0.648848, 0.217909, 1., 0.692176, 0.64356,  0.975085, 0.522904, 0.846523, 1.}, {0.0911374, 0.146149, 0.132664,  0.509687, 0.583224}, {0.636516, 0.557761, 0.875696, 0.682659,  0.523789}, {{0, 0}, {0, 0}, {1, 2}, {1, 1}, {1, 1}, {2, 4}, {1,  1}, {3, 4}}, 0.0528445, 0.574861, 0.806968, 0.033256,  0.619351}, {-23.2483, -11.2727, -24.5804}}, {{{-1., 0.646815,  0.359413, 0.384408, 0.401441, 0.954638, -1., 0.715853, 0.409323,  0.878538, 0.108116, 0.624715, -1., 0.263174, 0.745874, 0.598428,  0.0414911, 0.626658, -1., 0.188112, 0.722732, 0.358833, 0.102869,  0.135268, -1., -1., 0.147872, 0.551864, 0.0696131, 0.515917,  0.501057, -1., 0.192451, 0.685205, 0.114475, 0.546419,  0.476598, -1., 0.275881, 0.235938, 0.438304, 0.851883,  0.012707, -1., 0.490064, 0.839875, 0.810392, 0.386049,  0.301952, -1., -1., 0.117143, 0.451559, 0.283179, 0.166684,  0.969271, -1., 0.899695, 0.213566, 0.650767, 0.468214,  0.707244, -1., 0.528362, 0.536292, 0.921795, 0.230646,  0.25248, -1., 0.300354, 0.483491, 0.378763, 0.239773,  0.81029, -1., -1., 0.643616, 0.568371, 0.853725, 0.508338,  0.526473, -1., 0.116811, 0.570545, 0.341654, 0.557202,  0.217116, -1., 0.356979, 0.690887, 0.0889887, 0.509871,  0.828617, -1., 0.154595, 0.167194, 0.279226, 0.576137,  0.854242, -1.},  0.683703, {1., 0.900463, 0.336364, 0.043952, 0.040087, 0.332092,  1., 0.482639, 0.535614, 0.513614, 0.215281, 0.912094, 1., 0.19396,  0.956411, 0.998165, 0.555115, 0.503073, 1., 0.867423, 0.488294,  0.726498, 0.348478, 0.700228, 1.}, {0.209068, 0.150361, 0.494236,  0.0165255, 0.308605}, {0.813997, 0.450284, 0.976438, 0.976513,  0.331358}, {{1, 1}, {0, 4}, {2, 4}, {0, 4}, {2, 2}, {1, 0}, {0,  1}, {1, 3}}, 0.91467, 0.462825, 0.761232, 0.419263,  0.72071}, {-24.0102, -17.9719, -30.4303}}};

  for (unsigned int i = 0; i < sizeof (data) / sizeof (data[0]); ++i)
    {
      NormalDistribution prior_logbeta = 
        normal_distribution (data[i].inputs.logbetamean, 
                             data[i].inputs.logbetastddev);

      for (unsigned int j = 0; j < 4; ++j)
        {
          for (unsigned int k = 0; k < 5; ++k)
            {
              data[i].inputs.alpha[j * 5 * 5 + k * 5 + k] = drand48 ();
            }
        }

      for (unsigned int k = 0; k < 5; ++k)
        {
          data[i].inputs.gamma[k * 5 + k] = drand48 ();
        }

      float hq = 0;

      for (unsigned int k = 0; k < 5; ++k)
        {
          hq -= data[i].inputs.pz[k] * log (data[i].inputs.pz[k]);
        }

      float dqdlogbeta;
      float ddqddlogbeta;

      float q = qfunc (data[i].inputs.alpha,
                       5,
                       data[i].inputs.logbeta,
                       &dqdlogbeta,
                       &ddqddlogbeta,
                       data[i].inputs.pz,
                       data[i].inputs.ratings,
                       8,
                       &prior_logbeta.base,
                       0,
                       hq);

      assert (fabs (q - data[i].desired_output.q) <=
              1e-4 * (1 + fabs (q) + fabs (data[i].desired_output.q)) ||
              (fprintf (stderr, "%g ?= %g\n", q, data[i].desired_output.q),
               0));

      assert (fabs (dqdlogbeta - data[i].desired_output.dqdlogbeta) <=
              5e-3 * (1 + fabs (dqdlogbeta) + fabs (data[i].desired_output.dqdlogbeta)) ||
              (fprintf (stderr, "%g ?= %g\n", dqdlogbeta, data[i].desired_output.dqdlogbeta),
               0));

      assert (fabs (ddqddlogbeta - data[i].desired_output.ddqddlogbeta) <=
              5e-3 * (1 + fabs (ddqddlogbeta) + fabs (data[i].desired_output.ddqddlogbeta)) ||
              (fprintf (stderr, "%g ?= %g\n", ddqddlogbeta, data[i].desired_output.ddqddlogbeta),
               0));
    }
}

static void
test_qfunc_symmetric (void)
{
  QFuncTestDatum data[] = 
    {{{{-1., 0.506414, 0.763066, 0.864148, 0.217637, 0.638991, -1.,  0.274773, 0.13765, 0.869159, 0.938763, 0.0657044, -1., 0.987289,  0.374923, 0.922237, 0.757099, 0.173292, -1., 0.924639, 0.945799,  0.780586, 0.841934, 0.00996886, -1., -1., 0.482974, 0.0193545,  0.422671, 0.289259, 0.97656, -1., 0.256288, 0.558523, 0.0716221,  0.337569, 0.981515, -1., 0.420873, 0.202463, 0.398806, 0.915811,  0.433584, -1., 0.82754, 0.476569, 0.158712, 0.260292,  0.902901, -1., -1., 0.53077, 0.378126, 0.418357, 0.892932,  0.0477966, -1., 0.358771, 0.995687, 0.603673, 0.0712364,  0.102483, -1., 0.437164, 0.532051, 0.733667, 0.120968,  0.0162909, -1., 0.329588, 0.334861, 0.205157, 0.582707,  0.502048, -1., -1., 0.858292, 0.0464446, 0.322415, 0.599147,  0.327521, -1., 0.668319, 0.904058, 0.706215, 0.279725,  0.309548, -1., 0.908371, 0.102541, 0.208488, 0.207065,  0.471208, -1., 0.57049, 0.474821, 0.0860974, 0.454917,  0.240902, -1.},  0.13996, {1., 0.880941, 0.87221, 0.738854, 0.281668, 0.834496, 1.,  0.549794, 0.139707, 0.954147, 0.166177, 0.645737, 1., 0.433492,  0.674422, 0.856629, 0.737365, 0.330951, 1., 0.465934, 0.649564,  0.266158, 0.760461, 0.991113, 1.}, {0.563467, 0.811241, 0.519559,  0.851153, 0.682526}, {0.939031, 0.780706, 0.569485, 0.848029,  0.389237}, {{3, 4}, {2, 1}, {2, 4}, {2, 3}, {0, 0}, {2, 1}, {2,  3}, {2, 1}}, 0.640999, 0.615338, 0.681852, 0.7435,  0.207507}, {-53.2892, -19.1327, -42.852}}, {{{-1., 0.940916,  0.825223, 0.00613511, 0.876556, 0.474982, -1., 0.175659, 0.739977,  0.116095, 0.483868, 0.612192, -1., 0.928737, 0.596535, 0.632715,  0.929666, 0.989705, -1., 0.81583, 0.0632298, 0.0816369, 0.600468,  0.174831, -1., -1., 0.447892, 0.399785, 0.856968, 0.967324,  0.506976, -1., 0.574562, 0.850833, 0.0907684, 0.0319943,  0.398903, -1., 0.110856, 0.974674, 0.548126, 0.78671,  0.182119, -1., 0.378138, 0.915411, 0.857044, 0.192414,  0.562309, -1., -1., 0.852181, 0.775407, 0.591945, 0.387478,  0.40429, -1., 0.375623, 0.734977, 0.420154, 0.897314,  0.801061, -1., 0.884144, 0.329385, 0.865319, 0.402158,  0.773289, -1., 0.354711, 0.317193, 0.615448, 0.59117,  0.976573, -1., -1., 0.401782, 0.758404, 0.398756, 0.414265,  0.549601, -1., 0.982997, 0.806811, 0.026787, 0.145311,  0.607374, -1., 0.0718337, 0.606634, 0.247998, 0.806313,  0.18769, -1., 0.277248, 0.382678, 0.404155, 0.414401,  0.922537, -1.},  0.0654847, {1., 0.788707, 0.823231, 0.945964, 0.663702, 0.0303029,  1., 0.424475, 0.531699, 0.114101, 0.0473062, 0.617664, 1.,  0.504912, 0.96879, 0.439932, 0.54583, 0.898278, 1., 0.720793,  0.633619, 0.358141, 0.62103, 0.338114, 1.}, {0.229464, 0.94374,  0.698493, 0.27263, 0.440757}, {0.120509, 0.75253, 0.608927,  0.410454,  0.696034}, {{3, 2}, {0, 0}, {2, 0}, {2, 4}, {0, 0}, {3, 0}, {0,  4}, {0, 4}}, 0.220831, 0.494826, 0.363148, 0.0783694,  0.715919}, {-41.764, -12.8218, -37.0127}}, {{{-1., 0.526036,  0.923216, 0.532539, 0.81764, 0.805243, -1., 0.289597, 0.174398,  0.19661, 0.467129, 0.0601331, -1., 0.230658, 0.498117, 0.194499,  0.619376, 0.110149, -1., 0.745588, 0.585572, 0.208921, 0.414116,  0.524757, -1., -1., 0.0907457, 0.845773, 0.335746, 0.808838,  0.56471, -1., 0.922557, 0.803207, 0.991198, 0.759467,  0.63296, -1., 0.628809, 0.794588, 0.292338, 0.572827,  0.398151, -1., 0.29647, 0.0978389, 0.953451, 0.288002,  0.550883, -1., -1., 0.512267, 0.74453, 0.873886, 0.0261255,  0.421522, -1., 0.898756, 0.53814, 0.217287, 0.856812,  0.976199, -1., 0.734933, 0.226089, 0.0973451, 0.343239,  0.106124, -1., 0.431502, 0.805007, 0.770412, 0.707972,  0.135031, -1., -1., 0.707168, 0.816961, 0.419971, 0.584149,  0.194901, -1., 0.0724313, 0.546084, 0.558023, 0.773379,  0.173675, -1., 0.00794451, 0.340736, 0.916568, 0.197476,  0.273012, -1., 0.114647, 0.819223, 0.854237, 0.166888,  0.683145, -1.},  0.0142155, {1., 0.0838245, 0.458916, 0.548114, 0.307047, 0.266864,  1., 0.0389451, 0.963965, 0.112146, 0.194432, 0.492861, 1.,  0.405942, 0.338767, 0.0207572, 0.484916, 0.0652058, 1., 0.422199,  0.823281, 0.211904, 0.950559, 0.602976, 1.}, {0.969045, 0.0450161,  0.267414, 0.588761, 0.88522}, {0.5861, 0.7193, 0.281714,  0.618357,  0.547155}, {{3, 2}, {2, 0}, {3, 4}, {0, 1}, {2, 1}, {0, 1}, {0,  2}, {1, 0}}, 0.755334, 0.169568, 0.423925, 0.0542947,  0.349392}, {-40.3048, -11.0599, -30.234}}, {{{-1., 0.830801,  0.403167, 0.569379, 0.284187, 0.408602, -1., 0.579886, 0.357474,  0.333628, 0.805625, 0.610841, -1., 0.312458, 0.0662144, 0.216864,  0.725621, 0.726358, -1., 0.346915, 0.93515, 0.107264, 0.179203,  0.59158, -1., -1., 0.765583, 0.68334, 0.124908, 0.242188,  0.934782, -1., 0.280172, 0.555529, 0.958001, 0.52618,  0.700287, -1., 0.198055, 0.624373, 0.720555, 0.0894455,  0.885597, -1., 0.558159, 0.503691, 0.363825, 0.159239,  0.211244, -1., -1., 0.56854, 0.25656, 0.980036, 0.619664,  0.802958, -1., 0.573221, 0.855128, 0.377476, 0.868176,  0.293048, -1., 0.299599, 0.419475, 0.341996, 0.592762,  0.101544, -1., 0.795101, 0.621441, 0.503316, 0.215947,  0.236942, -1., -1., 0.11775, 0.139492, 0.0567087, 0.0256983,  0.54921, -1., 0.882931, 0.0766726, 0.406035, 0.746252,  0.30971, -1., 0.221544, 0.0285587, 0.878076, 0.0166619,  0.921945, -1., 0.609084, 0.53608, 0.4239, 0.820401,  0.813983, -1.},  0.91464, {1., 0.920584, 0.604454, 0.57704, 0.79689, 0.781092, 1.,  0.547745, 0.551342, 0.24768, 0.898161, 0.471073, 1., 0.145307,  0.501428, 0.58845, 0.249528, 0.116749, 1., 0.623352, 0.571789,  0.327583, 0.507665, 0.0872715, 1.}, {0.147888, 0.507181, 0.693682,  0.172632, 0.227305}, {0.902728, 0.116642, 0.375742, 0.446213,  0.354982}, {{2, 4}, {3, 2}, {3, 2}, {2, 0}, {2, 4}, {3, 0}, {2,  1}, {2, 4}}, 0.5653, 0.128062, 0.548052, 0.88391,  0.419992}, {-41.3858, -37.099, -53.2747}}, {{{-1., 0.626634,  0.959602, 0.634382, 0.303244, 0.00328259, -1., 0.387813, 0.306799,  0.795579, 0.916011, 0.239925, -1., 0.799617, 0.101897, 0.743379,  0.0126198, 0.89689, -1., 0.985255, 0.367637, 0.566407, 0.541908,  0.419955, -1., -1., 0.239575, 0.0183549, 0.657998, 0.999963,  0.61294, -1., 0.0587533, 0.0236162, 0.696719, 0.609657,  0.67094, -1., 0.716817, 0.90114, 0.693646, 0.431016, 0.9172, -1.,  0.799243, 0.950267, 0.418396, 0.02031, 0.813988, -1., -1.,  0.58263, 0.851989, 0.478402, 0.394033, 0.343056, -1., 0.833634,  0.820405, 0.39407, 0.730116, 0.774881, -1., 0.796789, 0.697351,  0.120458, 0.10394, 0.0799711, -1., 0.796211, 0.426812, 0.672925,  0.162771, 0.996968, -1., -1., 0.476545, 0.254529, 0.142461,  0.18298, 0.893914, -1., 0.40254, 0.664059, 0.788947, 0.550859,  0.568906, -1., 0.843654, 0.394878, 0.820743, 0.794025,  0.0468655, -1., 0.697527, 0.700285, 0.690085, 0.966894,  0.901316, -1.},  0.273473, {1., 0.01716, 0.804123, 0.904348, 0.796929, 0.762631, 1.,  0.661662, 0.721368, 0.903014, 0.360091, 0.997603, 1., 0.93242,  0.352156, 0.791185, 0.153949, 0.537543, 1., 0.531412, 0.99716,  0.107084, 0.840016, 0.831127, 1.}, {0.307075, 0.14019, 0.9387,  0.557654, 0.289915}, {0.336066, 0.0343528, 0.760725, 0.527284,  0.674404}, {{2, 0}, {2, 0}, {2, 3}, {0, 0}, {3, 1}, {3, 0}, {2,  4}, {2, 0}}, 0.312985, 0.857711, 0.167193, 0.676801,  0.380565}, {-43.2871,  0.517716, -73.537}}, {{{-1., 0.505555, 0.376008, 0.522852,  0.843022, 0.974143, -1., 0.378848, 0.415768, 0.00300619, 0.143015,  0.071773, -1., 0.275578, 0.0643057, 0.585361, 0.781858,  0.939512, -1., 0.0299529, 0.824636, 0.254574, 0.265108,  0.716968, -1., -1., 0.966925, 0.087381, 0.588306, 0.336403,  0.46137, -1., 0.711373, 0.0654547, 0.49338, 0.487227,  0.332525, -1., 0.649687, 0.490374, 0.344212, 0.260752,  0.374108, -1., 0.426069, 0.758851, 0.478894, 0.434596,  0.396116, -1., -1., 0.934215, 0.22432, 0.169489, 0.679148,  0.96729, -1., 0.136939, 0.581182, 0.342745, 0.50592,  0.425566, -1., 0.515727, 0.849365, 0.0186926, 0.0930408,  0.866041, -1., 0.358991, 0.674481, 0.832289, 0.491932,  0.932922, -1., -1., 0.91563, 0.353395, 0.0573361, 0.536807,  0.981416, -1., 0.129075, 0.887847, 0.857659, 0.0141261,  0.992135, -1., 0.306665, 0.514913, 0.508206, 0.56657,  0.790938, -1., 0.665549, 0.489514, 0.473529, 0.924897,  0.306558, -1.},  0.815033, {1., 0.64124, 0.432965, 0.373636, 0.899403, 0.287845, 1.,  0.375629, 0.836829, 0.917987, 0.158771, 0.487781, 1., 0.979171,  0.903861, 0.166635, 0.181116, 0.464257, 1., 0.395655, 0.600066,  0.390178, 0.798709, 0.906141, 1.}, {0.126537, 0.465281, 0.492151,  0.091108, 0.485297}, {0.0323165, 0.118515, 0.191705, 0.197452,  0.656688}, {{2, 0}, {0, 2}, {1, 1}, {1, 4}, {1, 1}, {2, 1}, {0,  1}, {3, 2}}, 0.281686, 0.273718, 0.0386809, 0.168907,  0.302515}, {-128.023, -387.621, -709.532}}, {{{-1., 0.369857,  0.872046, 0.987791, 0.838258, 0.974202, -1., 0.27198, 0.597613,  0.039549, 0.0680607, 0.145443, -1., 0.132332, 0.547398, 0.976953,  0.660146, 0.100015, -1., 0.428883, 0.785248, 0.462694, 0.443327,  0.147197, -1., -1., 0.51153, 0.424013, 0.27442, 0.844682,  0.141673, -1., 0.551967, 0.286629, 0.00642458, 0.167472,  0.279988, -1., 0.689016, 0.966876, 0.0994109, 0.134545,  0.556685, -1., 0.419477, 0.122458, 0.474399, 0.45667,  0.990594, -1., -1., 0.337211, 0.0117055, 0.0133427, 0.843397,  0.825681, -1., 0.587693, 0.738923, 0.998715, 0.684007,  0.0357252, -1., 0.452293, 0.99229, 0.516536, 0.755738,  0.763277, -1., 0.0254145, 0.417125, 0.621193, 0.206592,  0.605937, -1., -1., 0.294667, 0.146793, 0.749922, 0.615343,  0.957456, -1., 0.135088, 0.73658, 0.771946, 0.131775,  0.547395, -1., 0.997657, 0.773231, 0.447768, 0.51167,  0.545364, -1., 0.780941, 0.931232, 0.755932, 0.782087,  0.755526, -1.},  0.514108, {1., 0.13474, 0.575495, 0.149589, 0.219441, 0.987946, 1.,  0.825573, 0.534247, 0.261985, 0.852859, 0.0889929, 1., 0.762301,  0.130209, 0.305463, 0.0913358, 0.98907, 1., 0.682441, 0.793794,  0.545972, 0.208129, 0.751209, 1.}, {0.0378611, 0.763885, 0.452603,  0.237102, 0.903121}, {0.18839, 0.303014, 0.0176606, 0.915175,  0.362818}, {{1, 2}, {1, 2}, {2, 2}, {1, 0}, {1, 3}, {3, 4}, {3,  2}, {2, 0}}, 0.768767, 0.755676, 0.0623163, 0.273825,  0.00646623}, {-53.7854,  29.8585, -310.701}}, {{{-1., 0.625466, 0.756853, 0.182489,  0.0173961, 0.943025, -1., 0.963059, 0.636517, 0.809267, 0.191816,  0.925198, -1., 0.872632, 0.356664, 0.954714, 0.0220768,  0.684242, -1., 0.0536499, 0.937054, 0.106902, 0.321424,  0.284883, -1., -1., 0.181378, 0.0445855, 0.0475991, 0.278416,  0.555912, -1., 0.287733, 0.86511, 0.26102, 0.612887,  0.324673, -1., 0.228593, 0.451754, 0.421071, 0.399475,  0.355961, -1., 0.0950898, 0.466357, 0.377398, 0.671719, 0.0414399,  -1., -1., 0.529303, 0.270496, 0.350295, 0.756557, 0.347926, -1.,  0.225911, 0.302696, 0.478141, 0.792014, 0.938178, -1., 0.437586,  0.21712, 0.179127, 0.613505, 0.208993, -1., 0.765367, 0.758055,  0.21403, 0.853032, 0.670277, -1., -1., 0.291698, 0.836632,  0.181313, 0.628837, 0.762395, -1., 0.566135, 0.831018, 0.87228,  0.414469, 0.340224, -1., 0.528322, 0.394139, 0.622456, 0.402046,  0.0907363, -1., 0.177019, 0.443329, 0.788541, 0.881743,  0.411652, -1.},  0.685273, {1., 0.574511, 0.0287111, 0.741375, 0.393575, 0.737879,  1., 0.847398, 0.112538, 0.63118, 0.171744, 0.0163798, 1.,  0.240258, 0.216711, 0.83152, 0.488058, 0.846118, 1., 0.594255,  0.429475, 0.397321, 0.669099, 0.150926, 1.}, {0.640934, 0.515578,  0.257447, 0.465653, 0.0664229}, {0.486867, 0.516073, 0.0720779,  0.328544,  0.639469}, {{3, 1}, {0, 4}, {2, 2}, {2, 1}, {1, 0}, {0, 3}, {0,  3}, {3, 1}}, 0.403535, 0.440898, 0.156799, 0.623089,  0.163278}, {-35.5232, -35.1523, -83.9182}}, {{{-1., 0.224187,  0.325279, 0.135032, 0.317159, 0.629932, -1., 0.895804, 0.73771,  0.64806, 0.479006, 0.25487, -1., 0.222132, 0.390613, 0.0133531,  0.188448, 0.735265, -1., 0.87454, 0.941275, 0.859904, 0.0957959,  0.471005, -1., -1., 0.500377, 0.703105, 0.472707, 0.307727,  0.27619, -1., 0.377826, 0.337675, 0.990568, 0.646258,  0.482022, -1., 0.599965, 0.342508, 0.167252, 0.227151,  0.377832, -1., 0.951895, 0.153899, 0.0387036, 0.642567,  0.0773555, -1., -1., 0.212624, 0.1788, 0.546771, 0.606351,  0.712246, -1., 0.475695, 0.0740648, 0.298623, 0.436056,  0.0978686, -1., 0.73639, 0.308055, 0.789798, 0.615847,  0.136425, -1., 0.965547, 0.622546, 0.388696, 0.758593,  0.0136519, -1., -1., 0.468647, 0.349992, 0.116025, 0.936296,  0.256023, -1., 0.171192, 0.569254, 0.329946, 0.543777,  0.695498, -1., 0.495189, 0.0313226, 0.107721, 0.597629,  0.758799, -1., 0.723267, 0.317923, 0.981782, 0.622374,  0.75772, -1.},  0.695377, {1., 0.593087, 0.863781, 0.744068, 0.22673, 0.243095, 1.,  0.747756, 0.807772, 0.970706, 0.0719023, 0.178502, 1., 0.477826,  0.426929, 0.376405, 0.683312, 0.446503, 1., 0.319208, 0.778775,  0.924513, 0.723236, 0.00128528, 1.}, {0.796993, 0.302139,  0.965516, 0.305908, 0.203906}, {0.438358, 0.221448, 0.0791786,  0.960812,  0.690602}, {{3, 4}, {0, 2}, {0, 4}, {1, 4}, {3, 4}, {0, 4}, {2,  0}, {1, 3}}, 0.413676, 0.108472, 0.888909, 0.5121,  0.935851}, {-55.4552, -40.9305, -65.7061}}, {{{-1., 0.681543,  0.512505, 0.828788, 0.489348, 0.362335, -1., 0.733729, 0.904275,  0.766112, 0.361049, 0.936736, -1., 0.602136, 0.800596, 0.0551411,  0.73283, 0.163778, -1., 0.579148, 0.975963, 0.772018, 0.473176,  0.165472, -1., -1., 0.86749, 0.883109, 0.961076, 0.229621,  0.185947, -1., 0.370604, 0.132288, 0.740273, 0.823613,  0.636874, -1., 0.228013, 0.974161, 0.462563, 0.700138,  0.625877, -1., 0.173565, 0.407422, 0.967308, 0.462098,  0.594417, -1., -1., 0.43146, 0.19529, 0.988922, 0.428945,  0.563969, -1., 0.312182, 0.0278465, 0.199325, 0.378022,  0.941578, -1., 0.895559, 0.459052, 0.554409, 0.304703,  0.667546, -1., 0.484891, 0.0918462, 0.604565, 0.0416694,  0.311326, -1., -1., 0.684424, 0.637257, 0.579571, 0.716909,  0.252964, -1., 0.441967, 0.590649, 0.287963, 0.688995,  0.129785, -1., 0.562802, 0.0886383, 0.310973, 0.188207,  0.667244, -1., 0.629587, 0.756564, 0.883504, 0.999697,  0.144696, -1.},  0.664718, {1., 0.278939, 0.958028, 0.83337, 0.980294, 0.641682, 1.,  0.378457, 0.116462, 0.727329, 0.199715, 0.787808, 1., 0.828499,  0.038334, 0.0699303, 0.225006, 0.73986, 1., 0.727361, 0.881723,  0.557762, 0.110274, 0.970797, 1.}, {0.998219, 0.558065, 0.965578,  0.306079, 0.719281}, {0.600037, 0.132208, 0.325785, 0.0775988,  0.22158}, {{0, 2}, {3, 4}, {0, 4}, {0, 1}, {3, 2}, {3, 0}, {3,  0}, {3, 1}}, 0.0157461, 0.598456, 0.877883, 0.433772,  0.187247}, {-72.6878, -54.0214, -89.4164}}};

  for (unsigned int i = 0; i < sizeof (data) / sizeof (data[0]); ++i)
    {
      NormalDistribution prior_logbeta = 
        normal_distribution (data[i].inputs.logbetamean, 
                             data[i].inputs.logbetastddev);

      for (unsigned int j = 0; j < 4; ++j)
        {
          for (unsigned int k = 0; k < 5; ++k)
            {
              data[i].inputs.alpha[j * 5 * 5 + k * 5 + k] = drand48 ();
            }
        }

      for (unsigned int k = 0; k < 5; ++k)
        {
          data[i].inputs.gamma[k * 5 + k] = drand48 ();
        }

      float hq = 0;

      for (unsigned int k = 0; k < 5; ++k)
        {
          hq -= data[i].inputs.pz[k] * log (data[i].inputs.pz[k]);
        }

      float dqdlogbeta;
      float ddqddlogbeta;

      float q = qfunc (data[i].inputs.alpha,
                       5,
                       data[i].inputs.logbeta,
                       &dqdlogbeta,
                       &ddqddlogbeta,
                       data[i].inputs.pz,
                       data[i].inputs.ratings,
                       8,
                       &prior_logbeta.base,
                       1,
                       hq);

      assert (fabs (q - data[i].desired_output.q) <=
              1e-4 * (1 + fabs (q) + fabs (data[i].desired_output.q)) ||
              (fprintf (stderr, "%g ?= %g\n", q, data[i].desired_output.q),
               0));

      assert (fabs (dqdlogbeta - data[i].desired_output.dqdlogbeta) <=
              1e-4 * (1 + fabs (dqdlogbeta) + fabs (data[i].desired_output.dqdlogbeta)) ||
              (fprintf (stderr, "%g ?= %g\n", dqdlogbeta, data[i].desired_output.dqdlogbeta),
               0));

      assert (fabs (ddqddlogbeta - data[i].desired_output.ddqddlogbeta) <=
              1e-4 * (1 + fabs (ddqddlogbeta) + fabs (data[i].desired_output.ddqddlogbeta)) ||
              (fprintf (stderr, "%g ?= %g\n", ddqddlogbeta, data[i].desired_output.ddqddlogbeta),
               0));
    }
}

typedef struct _DQFuncTestDatum DQFuncTestDatum ;
struct _DQFuncTestDatum 
{ 
  struct
    {
      float    alpha[4 * 5 * 5];
      float    logbeta;
      float    gamma[5 * 5];
      float    pz[5];
      float    priorz[5];
      Rating    ratings[8];
      float    alphastddev;
      float    logbetamean;
      float    logbetastddev;
      float    gammamean;
      float    gammastddev;
    }                   inputs;
  float                dalpha[4 * 5 * 5];
};

static void
test_dqfunc (void)
{
  DQFuncTestDatum data[] = 
    {{{{-1., 0.736485, 0.873324, 0.497292, 0.0412989, 0.611716, -1.,  0.151447, 0.340409, 0.727551, 0.487806, 0.614378, -1., 0.68367,  0.403892, 0.983422, 0.374595, 0.0544282, -1., 0.570288, 0.179816,  0.478257, 0.848331, 0.158461, -1., -1., 0.147899, 0.121185,  0.928692, 0.270048, 0.411414, -1., 0.247861, 0.4314, 0.22875,  0.799698, 0.0964145, -1., 0.0909912, 0.501199, 0.311892, 0.482036,  0.407321, -1., 0.0973068, 0.32847, 0.107441, 0.352893,  0.527019, -1., -1., 0.148654, 0.629184, 0.504562, 0.368558,  0.000755249, -1., 0.508, 0.57587, 0.0985092, 0.589342,  0.260139, -1., 0.14447, 0.86976, 0.789644, 0.163724,  0.0534789, -1., 0.368561, 0.477752, 0.681688, 0.646157,  0.271254, -1., -1., 0.149282, 0.574247, 0.293264, 0.744235,  0.000627498, -1., 0.945063, 0.788702, 0.375677, 0.999872,  0.437063, -1., 0.212832, 0.277168, 0.410531, 0.176925,  0.0683616, -1., 0.407408, 0.620887, 0.0132007, 0.0148826,  0.0388476, -1.},  0.143136, {1., 0.331513, 0.368725, 0.767594, 0.993854, 0.757265,  1., 0.0754611, 0.0233592, 0.993226, 0.812202, 0.286759, 1.,  0.647682, 0.993354, 0.375139, 0.0739276, 0.370514, 1., 0.582823,  0.198214, 0.00556604, 0.963106, 0.961936, 1.}, {0.185013,  0.990683, 0.924259, 0.818801, 0.853501}, {0.621958, 0.156665,  0.824947, 0.0962354,  0.546497}, {{0, 2}, {1, 0}, {3, 2}, {3, 4}, {1, 0}, {3, 1}, {3,  3}, {3, 0}}, 0.133306, 0.831721, 0.284033, 0.259738,  0.485624}, {0.123516, 0.0166542, -0.199263, 0.0219477, 0.0371449,  0.100581, 0.645935, -0.972068, 0.137555, 0.087997, 0.114308,  0.0987753, -0.430198, 0.0911852, 0.12593, 0.0542609,  0.109543, -0.786302, 0.535096, 0.0874016, 0.138758,  0.0983338, -0.920685, 0.14222, 0.541373, -0.199755, 0.0604215,  0.062313, 0.0245423, 0.0524782, -2.04602, 1.22449, 0.290148,  0.23477, 0.296617, -1.98988, 0.322159, 1.1416, 0.324182,  0.20194, -1.6684, 0.181775, 0.198141, 1.00513, 0.283356, -1.74301,  0.292524, 0.220373, 0.18026, 1.04986, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0.383979, -0.0548576, -0.11634, -0.0791388, -0.133643, -0.115243,  2.11815, -0.797462, -0.729114, -0.476328, -0.766019, -0.491262,  1.95339, -0.321401, -0.37471, -0.467085, -0.319288, -0.235811,  1.48754, -0.465361, -0.619441, -0.248131, -0.249559, -0.269613,  1.38674}}, {{{-1., 0.838367, 0.908895, 0.18581, 0.115109,  0.255543, -1., 0.710681, 0.180244, 0.152003, 0.293607,  0.525667, -1., 0.189561, 0.227744, 0.474807, 0.672167,  0.567603, -1., 0.0710794, 0.64986, 0.575931, 0.0211055,  0.937774, -1., -1., 0.818139, 0.291898, 0.761368, 0.45215,  0.979772, -1., 0.383004, 0.575557, 0.337041, 0.724229,  0.672323, -1., 0.395313, 0.185038, 0.430622, 0.146656,  0.205752, -1., 0.957294, 0.955815, 0.474489, 0.63815,  0.886215, -1., -1., 0.305956, 0.898557, 0.617044, 0.948441,  0.487817, -1., 0.606659, 0.855677, 0.496291, 0.508044,  0.223656, -1., 0.280119, 0.15925, 0.783815, 0.551333,  0.884806, -1., 0.974211, 0.353194, 0.404677, 0.679053,  0.0169174, -1., -1., 0.397378, 0.930188, 0.0409035, 0.130703,  0.0914228, -1., 0.0316311, 0.423859, 0.182262, 0.603606,  0.424972, -1., 0.568183, 0.685971, 0.0955616, 0.201316,  0.288063, -1., 0.526722, 0.311746, 0.649983, 0.403258,  0.55251, -1.},  0.958552, {1., 0.245306, 0.724204, 0.535593, 0.561174, 0.315118,  1., 0.683301, 0.40489, 0.469751, 0.283487, 0.259442, 1., 0.222628,  0.866145, 0.858515, 0.691259, 0.536657, 1., 0.770584, 0.657199,  0.403196, 0.00993542, 0.458837, 1.}, {0.00721526, 0.999938,  0.457425, 0.500285, 0.761909}, {0.275734, 0.921832, 0.939111,  0.446792,  0.592433}, {{2, 4}, {3, 1}, {0, 0}, {3, 2}, {3, 0}, {0, 2}, {2,  4}, {1, 1}}, 0.516942, 0.46936, 0.163305, 0.332992,  0.294314}, {0.0149314, 0.000279324, -0.0185844, 0.00153178,  0.00184193, -2.43539, 4.55498, -2.55516, 0.209767,  0.225799, -1.12113, 0.0392006, 0.90249, 0.0941821,  0.0852554, -1.25458, 0.0299562, -1.26535, 2.34634,  0.143642, -1.93838, 0.0589574, -1.73642, 0.0229463, 3.5929,  0.017489, -0.0186642, 0.000601943, 0.000176942, 0.000396327,  0.0138226, -0.19291, 0.065538, 0.0396649, 0.0738841,  0.0121357, -1.17903, 1.08877, 0.0286152, 0.049517,  0.0278387, -1.24632, 0.0500424, 1.16139, 0.00704917,  0.0115443, -1.94649, 0.0264337, 0.013842, 1.89467, 0.0354631,  0.00117664, 0.000250878, 0.000522763, -0.0374134, 0.101225,  4.90225, 0.0742481, 0.0387835, -5.1165, 0.0408206, 0.0856995,  2.084, 0.0739653, -2.28448, 0.0239374, 0.0438921, 0.0183947,  2.50861, -2.59484, 0.102433, 0.0895633, 0.0437896,  0.246212, -0.481997, 0.0302155, -0.0175351, -0.0184974, 0.00324751,  0.00256947, -2.22804, 3.9328, -2.16396, 0.159568,  0.299626, -1.1418, -1.11146, 2.15595, 0.0560748,  0.0412439, -1.10998, -1.15691, -1.18683, 3.39047,  0.0632539, -1.80817, -1.91298, -1.84613, 0.0954449,  5.47183}}, {{{-1., 0.603215, 0.30479, 0.641733, 0.757657,  0.832631, -1., 0.647592, 0.238537, 0.747722, 0.373794,  0.640376, -1., 0.238599, 0.290297, 0.873509, 0.878467,  0.962865, -1., 0.368464, 0.934398, 0.431676, 0.370432,  0.851522, -1., -1., 0.465038, 0.268371, 0.03744, 0.557207,  0.861823, -1., 0.96358, 0.395707, 0.79955, 0.0291924,  0.315989, -1., 0.157171, 0.051828, 0.655399, 0.675612,  0.918572, -1., 0.761531, 0.78189, 0.797145, 0.955707,  0.393067, -1., -1., 0.847492, 0.365469, 0.585275, 0.541545,  0.382454, -1., 0.0970983, 0.547835, 0.984338, 0.520631,  0.133518, -1., 0.152128, 0.184788, 0.491438, 0.817529,  0.994957, -1., 0.13296, 0.83604, 0.141917, 0.0763855,  0.371428, -1., -1., 0.0541497, 0.344772, 0.120679, 0.978361,  0.206658, -1., 0.979303, 0.535403, 0.436816, 0.824204,  0.882205, -1., 0.987568, 0.452478, 0.303573, 0.748687,  0.83544, -1., 0.267691, 0.812135, 0.931158, 0.840483,  0.134731, -1.},  0.976095, {1., 0.78924, 0.764097, 0.763302, 0.921946, 0.444468, 1.,  0.643419, 0.784941, 0.715288, 0.465165, 0.108016, 1., 0.348125,  0.891084, 0.58296, 0.120448, 0.895646, 1., 0.587511, 0.834273,  0.285007, 0.627956, 0.775376, 1.}, {0.903115, 0.444524, 0.493225,  0.799281, 0.113875}, {0.680427, 0.729923, 0.877335, 0.669407,  0.037008}, {{1, 3}, {3, 3}, {1, 1}, {1, 2}, {2, 0}, {1, 1}, {0,  0}, {0, 0}}, 0.944982, 0.162047, 0.204242, 0.928992,  0.596857}, {-0.304222, 0.0637188, 0.140685, 0.0575268,  0.0422912, -2.34253, 2.21067, 0.0278888, 0.0825898,  0.0213803, -2.55651, 0.030362, 2.36106, 0.0881938,  0.0768862, -4.2146, 0.0277349, 0.022169, 4.05732,  0.107369, -0.601109, 0.0127365, 0.0149846, 0.00417942, 0.569209,  8.44928, -4.62083, -2.1053, -1.85864, 0.13549, 0.0322445,  2.1536, -1.15519, -1.0687, 0.0380395, 0.283383, -2.48574,  3.04278, -1.10728, 0.26686, 0.100864, -4.1471, -2.07119, 6.04132,  0.0761036, 0.0101925, -0.594676, -0.295806, -0.273626,  1.15391, -0.147763, 0.0166922, 0.0599951, 0.0334778,  0.0375978, -1.15249, 1.07111, 0.0582456, 0.0176085,  0.00552824, -1.28906, 0.0558512, 1.13131, 0.0531596,  0.0487457, -2.0839, 0.0157607, 0.00984157, 1.96133,  0.0969716, -0.300203, 0.0128039, 0.0152363, 0.00696302, 0.2652,  2.09257, 0.127531, 0.0589698, -2.29004, 0.010973, 0.0442124,  1.08742, 0.00568795, -1.16132, 0.0240023, 0.00992794, 0.00851147,  1.25755, -1.30262, 0.0266274, 0.061559, 0.01889,  0.015005, -0.163164, 0.0677097, 0.00230064, 0.00167748,  0.0021339, -0.288343,  0.282231}}, {{{-1., 0.270963, 0.621282, 0.808545, 0.701211,  0.683452, -1., 0.787009, 0.523538, 0.0732553, 0.908075,  0.883894, -1., 0.0790134, 0.58003, 0.108794, 0.770019,  0.398586, -1., 0.850108, 0.231459, 0.100613, 0.361578,  0.905126, -1., -1., 0.0694115, 0.896371, 0.432586, 0.308268,  0.798448, -1., 0.275089, 0.624041, 0.607057, 0.114997,  0.48808, -1., 0.100503, 0.533802, 0.206921, 0.604185,  0.02149, -1., 0.953772, 0.0981267, 0.834166, 0.622904,  0.103664, -1., -1., 0.866668, 0.733553, 0.261325, 0.198539,  0.797256, -1., 0.837183, 0.828739, 0.89027, 0.998808,  0.562094, -1., 0.204698, 0.283213, 0.883811, 0.0740145,  0.104195, -1., 0.749411, 0.67689, 0.469829, 0.0827048,  0.795639, -1., -1., 0.578763, 0.635663, 0.459801, 0.691975,  0.712096, -1., 0.902109, 0.198476, 0.493436, 0.914839,  0.0649267, -1., 0.369737, 0.603166, 0.916031, 0.502833,  0.165039, -1., 0.319953, 0.0322201, 0.428818, 0.0608443,  0.570542, -1.},  0.35533, {1., 0.958989, 0.97814, 0.774903, 0.776567, 0.323326, 1.,  0.518338, 0.0829277, 0.0644709, 0.421217, 0.319862, 1., 0.589491,  0.149632, 0.35629, 0.950125, 0.986325, 1., 0.2336, 0.853458,  0.785086, 0.666372, 0.20138, 1.}, {0.424639, 0.724242, 0.09583,  0.84605, 0.46565}, {0.746102, 0.320927, 0.0694835, 0.142324,  0.227764}, {{2, 3}, {3, 2}, {1, 0}, {2, 4}, {3, 3}, {1, 4}, {2,  1}, {3, 1}}, 0.238, 0.00501262, 0.721107, 0.907902,  0.648508}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0.16665, 0.16799, 0.0516311,  0.100061, -0.486333, -0.922833, 1.43645, 0.23295,  0.141598, -0.888169, -0.102815, 0.0199093, 0.16636,  0.0346093, -0.118064, -0.932997, 0.15547, 0.357006,  1.53312, -1.1126, -0.489628, 0.0611273, 0.0826286, 0.173318,  0.172553, 1.21137, -0.52134, 0.102138, -0.405469, -0.386695,  0.184894, 1.36824, 0.174656, -0.856467, -0.871323,  0.0157383, -0.107371, 0.272517, -0.0878532, -0.0930311,  0.1566, -0.709819, 0.476246, 1.09429, -1.01732,  0.121071, -0.501641, 0.282611, -0.562117, 0.660077,  1.28334, -0.470866, -0.481388, -0.445905, 0.11482, 0.185479,  1.10024, -0.891802, -0.647293, 0.253381, 0.0174837, -0.0779364,  0.131844, -0.0986646, 0.0272735, 0.154417, -0.928594, -0.756203,  1.16896, 0.361424, 0.27106, -0.510385, -0.404106, -0.538565,  1.182}}, {{{-1., 0.855381, 0.364817, 0.957777, 0.662183,  0.621781, -1., 0.511359, 0.172691, 0.995811, 0.420401,  0.0867197, -1., 0.448449, 0.899981, 0.574351, 0.621069,  0.702347, -1., 0.579054, 0.504868, 0.478745, 0.474583,  0.341054, -1., -1., 0.499855, 0.757638, 0.566681, 0.692546,  0.644474, -1., 0.392822, 0.608904, 0.0303629, 0.0226929,  0.881463, -1., 0.436214, 0.0345517, 0.602292, 0.794743,  0.987764, -1., 0.13457, 0.0279406, 0.173674, 0.285417,  0.555517, -1., -1., 0.523073, 0.694928, 0.810834, 0.214462,  0.0232179, -1., 0.93729, 0.244153, 0.521916, 0.378744,  0.544468, -1., 0.635249, 0.491553, 0.356051, 0.663005,  0.199035, -1., 0.457001, 0.753759, 0.868262, 0.211271,  0.322431, -1., -1., 0.725819, 0.694589, 0.925853, 0.766914,  0.202746, -1., 0.999661, 0.115019, 0.552452, 0.179528,  0.062371, -1., 0.870866, 0.0305363, 0.800784, 0.517903,  0.235617, -1., 0.538983, 0.444733, 0.854898, 0.0365818,  0.0819818, -1.},  0.690974, {1., 0.986636, 0.825311, 0.759551, 0.965155, 0.292047,  1., 0.899458, 0.992637, 0.762409, 0.292386, 0.784439, 1.,  0.440184, 0.582881, 0.230015, 0.913574, 0.409648, 1., 0.782097,  0.712112, 0.677957, 0.870665, 0.337364, 1.}, {0.857214, 0.641375,  0.788683, 0.646391, 0.870578}, {0.816064, 0.0291319, 0.681236,  0.578532,  0.916606}, {{3, 0}, {2, 2}, {2, 0}, {1, 4}, {0, 1}, {3, 4}, {2,  0}, {2, 0}}, 0.0364953, 0.918826, 0.286146, 0.132167,  0.596311}, {1.49192, -1.67392, 0.0979165, 0.0299872, 0.0540913,  0.0418071, -0.216182, 0.0521139, 0.102442, 0.0198188,  0.0738939, -1.43012, 1.25798, 0.0698714, 0.0283763,  0.0480917, -1.24616, 0.0372508, 1.11318, 0.0476424,  0.0704748, -1.66313, 0.0748656, 0.0977264, 1.42006, 1.47718,  0.0740466, 0.0442674, 0.0648017, -1.6603, 0.0379183, 1.00953,  0.0626551, 0.0407078, -1.15081, 0.152917, 0.0275522, 1.17713,  0.0669969, -1.4246, 0.0442348, 0.0301277, 0.0204962,  1.08262, -1.17748, 0.16588, 0.124018, 0.099229,  0.0578818, -0.447009, 0.582777, 0.273499, -1.51661, 0.154011,  0.506326, -3.32171, 3.9931, -1.19636, 0.333426, 0.191541, -4.38663,  0.240805, 3.67729, 0.200903, 0.267626, -3.59399,  0.149542, -0.912501, 4.13137, 0.225583, -5.03937,  0.137472, -1.22731, 0.40859, 5.72061, 1.353, 0.0978304, 0.104122,  0.0656302, -1.62058, -1.09605, 2.02789, 0.0374915,  0.219106, -1.18844, -1.35516, 0.276409, 2.30309,  0.0550587, -1.2794, -1.23121, 0.103343, 0.181526,  2.13723, -1.19089, -1.59035, 0.0648507, 0.332011, 0.303252,  0.890233}}, {{{-1., 0.335945, 0.0561307, 0.218593, 0.186663,  0.553848, -1., 0.344019, 0.540636, 0.315998, 0.216483,  0.486805, -1., 0.899261, 0.527316, 0.570093, 0.616226,  0.0831977, -1., 0.498184, 0.888857, 0.0376945, 0.166592,  0.461688, -1., -1., 0.970031, 0.751549, 0.0344253, 0.865377,  0.634085, -1., 0.695418, 0.815832, 0.678714, 0.0802375,  0.351399, -1., 0.275196, 0.362716, 0.863754, 0.864595,  0.375935, -1., 0.8354, 0.293661, 0.248368, 0.292737,  0.337216, -1., -1., 0.404804, 0.210674, 0.126145, 0.875528,  0.434774, -1., 0.459125, 0.0917198, 0.0101506, 0.800688,  0.763707, -1., 0.275887, 0.331436, 0.720451, 0.412307,  0.000691316, -1., 0.968721, 0.856697, 0.547713, 0.624757,  0.133321, -1., -1., 0.563036, 0.299344, 0.33202, 0.796104,  0.158231, -1., 0.0886706, 0.205875, 0.920576, 0.723458,  0.629546, -1., 0.114155, 0.910426, 0.922769, 0.865839,  0.838267, -1., 0.578989, 0.202318, 0.453532, 0.837576,  0.610269, -1.},  0.345621, {1., 0.905819, 0.212819, 0.476948, 0.782586, 0.606474,  1., 0.8808, 0.680844, 0.624355, 0.517804, 0.674925, 1., 0.760267,  0.900897, 0.888258, 0.56077, 0.849842, 1., 0.978128, 0.0224192,  0.722503, 0.270852, 0.77581, 1.}, {0.568888, 0.884927, 0.660584,  0.430188, 0.663069}, {0.672108, 0.183636, 0.647602, 0.0565946,  0.791308}, {{1, 3}, {3, 0}, {1, 3}, {1, 3}, {1, 3}, {3, 1}, {1,  0}, {2, 1}}, 0.502792, 0.0232475, 0.538791, 0.116383,  0.742525}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 1.96863, 0.171412, 0.233401, -2.57217,  0.198728, -0.793684, 4.59423, 0.4187, -4.64794,  0.428699, -0.328265, 0.412485, 2.78373, -3.2739,  0.405942, -0.447435, 0.160173, 0.319472, -0.199129,  0.166919, -0.478844, 0.488251, 0.458583, -3.31666, 2.84867,  0.504705, -0.734413, 0.0912361, 0.10281, 0.0356625,  0.0961444, -0.52032, 0.0928928, 0.156107, 0.175175,  0.0495774, -0.881081, 0.63123, 0.104064, 0.0962094,  0.0349672, -0.553756, 0.0966731, 0.397494, 0.0246219,  0.0457109, -0.866097, 0.0634363, 0.127023, 0.629927,  0.267416, -0.686062, 0.170838, 0.16313, 0.0846782, -0.956637,  0.25812, 0.323973, 0.274532, 0.100012, -0.821483, -0.805614,  1.27671, 0.264513, 0.0858725, -0.546912, -0.541813, 0.0686075,  0.921157, 0.0989612, -0.706583, -0.775376, 0.0938419, 0.129382,  1.25874}}, {{{-1., 0.12235, 0.650533, 0.555612, 0.892683,  0.144222, -1., 0.628114, 0.833109, 0.62183, 0.368413,  0.0592258, -1., 0.948182, 0.961247, 0.938225, 0.396157,  0.276074, -1., 0.777611, 0.290622, 0.339562, 0.484767,  0.274819, -1., -1., 0.267375, 0.800771, 0.368384, 0.532294,  0.145024, -1., 0.150239, 0.812772, 0.639611, 0.000801984,  0.522125, -1., 0.979663, 0.0177806, 0.632389, 0.462899,  0.0314809, -1., 0.056534, 0.694165, 0.0667424, 0.755407,  0.278923, -1., -1., 0.403542, 0.72718, 0.27064, 0.00410479,  0.136168, -1., 0.926409, 0.902256, 0.471811, 0.991143,  0.77617, -1., 0.0894839, 0.8322, 0.990341, 0.254045,  0.109821, -1., 0.814419, 0.357952, 0.791146, 0.07834,  0.757885, -1., -1., 0.663787, 0.724404, 0.322933, 0.478962,  0.260245, -1., 0.997224, 0.0522936, 0.474857, 0.124077,  0.0708146, -1., 0.150038, 0.00304624, 0.132934, 0.294644,  0.0605538, -1., 0.170846, 0.142593, 0.0405988, 0.950733,  0.356427, -1.},  0.78464, {1., 0.249453, 0.872393, 0.598542, 0.120853, 0.525049, 1.,  0.549459, 0.11958, 0.860608, 0.527825, 0.497166, 1., 0.644723,  0.736531, 0.457011, 0.347128, 0.641677, 1., 0.603597, 0.162366,  0.286574, 0.47083, 0.461005, 1.}, {0.121768, 0.335841, 0.114403,  0.676364, 0.872315}, {0.463449, 0.515861, 0.555511, 0.347266,  0.913989}, {{1, 2}, {0, 2}, {2, 0}, {2, 4}, {0, 3}, {1, 3}, {0,  0}, {1, 1}}, 0.396281, 0.694903, 0.819441, 0.416823,  0.751559}, {0.422613, 0.0589197, -0.248353, -0.244071,  0.0108906, -0.580481, 1.9097, -0.682171, -0.701665,  0.0546129, -0.218841, 0.062792, 0.389131, -0.241779,  0.00869668, -1.42669, 0.182527, -1.24486, 2.40991,  0.0791143, -1.63212, 0.251221, -1.72904, -1.62226, 4.73219,  0.68654, -0.224174, -0.253604, -0.232652, 0.02389, 0.148628,  1.09183, -0.589097, -0.701638, 0.0502748, 0.0661846, -0.229615,  0.342645, -0.242982, 0.063767, 0.0977336, -1.34063, -1.11758,  2.01522, 0.345261, 0.116361, -1.45153, -1.81004, -1.62269, 4.7679,  0.163106, 0.0198399, 0.00976109, 0.0265483, -0.219255, -0.630167,  1.27698, 0.0187333, 0.0197516, -0.685302, -0.245143, 0.00894575,  0.438722, 0.0402912, -0.242816, -1.45039, 0.160415, 0.220049,  2.50528, -1.43536, -1.7474, 0.0636116, 0.303383, 0.0684218,  1.31198, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0}}, {{{-1., 0.958372, 0.362431, 0.0696951, 0.109882,  0.354774, -1., 0.200064, 0.783121, 0.639052, 0.89377,  0.0782968, -1., 0.447279, 0.524649, 0.217405, 0.205982,  0.983831, -1., 0.00878738, 0.661894, 0.858716, 0.0698417,  0.612506, -1., -1., 0.966992, 0.0392744, 0.653018, 0.860947,  0.0086201, -1., 0.676844, 0.583323, 0.751065, 0.653846,  0.476779, -1., 0.800203, 0.112014, 0.760076, 0.398483,  0.352923, -1., 0.587365, 0.542671, 0.192501, 0.369092,  0.578578, -1., -1., 0.880776, 0.333785, 0.299251, 0.966072,  0.913785, -1., 0.294511, 0.646232, 0.105124, 0.905165,  0.617667, -1., 0.0629089, 0.354059, 0.251319, 0.140888,  0.262706, -1., 0.242045, 0.491243, 0.742405, 0.909783,  0.65468, -1., -1., 0.948572, 0.549905, 0.540691, 0.0761025,  0.0677954, -1., 0.216119, 0.24144, 0.110031, 0.154011,  0.921608, -1., 0.595208, 0.00490672, 0.248846, 0.303941,  0.532299, -1., 0.650848, 0.997527, 0.163053, 0.269593,  0.408803, -1.},  0.506284, {1., 0.420648, 0.35981, 0.754123, 0.557712, 0.870744, 1.,  0.819119, 0.67802, 0.489917, 0.654624, 0.577679, 1., 0.56799,  0.335906, 0.733016, 0.982471, 0.563083, 1., 0.0870605, 0.429075,  0.450173, 0.912235, 0.0895335, 1.}, {0.266021, 0.18058, 0.503432,  0.583249, 0.845373}, {0.820771, 0.749309, 0.0255368, 0.974629,  0.0016516}, {{3, 4}, {0, 3}, {3, 3}, {1, 3}, {2, 3}, {0, 2}, {0,  3}, {1, 4}}, 0.0712886, 0.53562, 0.320005, 0.423973,  0.503299}, {0.899981, 0.0349252, -0.347486, -0.730149, 0.14273,  0.0698153, 0.660884, -0.209357, -0.564905, 0.0435628, 0.0784003,  0.303321, 0.979692, -1.50605, 0.144639, 0.258047,  0.262984, -0.895325, 0.00952584, 0.364768, 0.198158,  0.142953, -0.873382, -2.59006, 3.12233, 0.66541, 0.0254557,  0.118644, -0.398503, -0.411007, 0.0816634, 0.435295,  0.026949, -0.268131, -0.275776, 0.0790555, 0.106051,  1.22914, -0.773239, -0.641008, 0.0784712, 0.142973, 0.154199,  0.487524, -0.863168, 0.155905, 0.278723, 0.207937, -1.25568,  0.613117, 0.337517, 0.0148975, 0.0369185, -0.402264, 0.0129316,  0.00904887, 0.216552, 0.0252818, -0.285498, 0.0346155, 0.0255096,  0.0411017, 0.601812, -0.732073, 0.0636504, 0.0795066, 0.0954934,  0.0780186, -0.333758, 0.0807394, 0.0948156, 0.0625038,  0.0473482, -1.33027, 1.12561, 0.648486, 0.0255781,  0.0495593, -0.391037, -0.332587, 0.0641267, 0.37708,  0.0501378, -0.251528, -0.239816, 0.17001, 0.0475758,  1.15343, -0.753486, -0.617526, 0.176081, 0.1607, 0.11002,  0.4305, -0.877301, 0.0728743, 0.290971, 0.243828, -1.20903,  0.601355}}, {{{-1., 0.199713, 0.586989, 0.441501, 0.940216,  0.112653, -1., 0.157915, 0.991329, 0.0279814, 0.0231196,  0.891894, -1., 0.810749, 0.52455, 0.43987, 0.0465207,  0.989978, -1., 0.775241, 0.414334, 0.0718913, 0.988327,  0.703952, -1., -1., 0.878714, 0.751886, 0.564354, 0.200653,  0.679, -1., 0.164897, 0.122853, 0.260437, 0.566347,  0.00698232, -1., 0.131524, 0.232455, 0.543228, 0.115089,  0.320775, -1., 0.707906, 0.103357, 0.068568, 0.330797,  0.932665, -1., -1., 0.689024, 0.996677, 0.342471, 0.228713,  0.81031, -1., 0.24479, 0.778117, 0.0280602, 0.13131,  0.0798934, -1., 0.655264, 0.767623, 0.564963, 0.0729111,  0.52374, -1., 0.535168, 0.0217351, 0.957822, 0.202965,  0.827262, -1., -1., 0.918378, 0.889254, 0.872167, 0.894597,  0.229354, -1., 0.892578, 0.529697, 0.665884, 0.419044,  0.647787, -1., 0.75158, 0.637824, 0.287734, 0.567894,  0.0963155, -1., 0.8702, 0.722772, 0.494983, 0.572575,  0.335032, -1.},  0.701037, {1., 0.53716, 0.369611, 0.50777, 0.782659, 0.647906, 1.,  0.497443, 0.613173, 0.553304, 0.755328, 0.967747, 1., 0.947289,  0.13426, 0.107541, 0.216167, 0.309465, 1., 0.846526, 0.539647,  0.119852, 0.439265, 0.123754, 1.}, {0.0446646, 0.547276, 0.104233,  0.422718, 0.507504}, {0.177666, 0.596463, 0.640059, 0.859598,  0.680222}, {{0, 2}, {0, 3}, {0, 1}, {3, 2}, {3, 3}, {2, 2}, {0,  3}, {1, 4}}, 0.98329, 0.0867547, 0.10427, 0.712475,  0.0360009}, {0.298981, -0.063409, -0.0778388, -0.163718,  0.00598475, 0.347747, 2.17287, -0.785799, -2.14729, 0.412468,  0.0874844, -0.194934, 0.477965, -0.402353, 0.0318379,  0.153062, -0.513886, -0.801635, 1.08461, 0.0778504,  0.193276, -0.637592, -0.962281, -1.93829, 3.34489, 0.0760757,  0.00172381, 0.002226, 0.00324865, -0.0832741, 0.0284935, 0.840733,  0.0803207, 0.087425, -1.03697, 0.00657377, 0.0203012, 0.154562,  0.0157939, -0.197231, 0.0303303, 0.0718951, 0.0474928,  0.680651, -0.830369, 0.084279, 0.0904016, 0.0532848,  0.0158375, -0.243803, 0.0749138, 0.00248814, -0.0886985,  0.00500346, 0.00629306, 0.0227556, 0.874899, -1.03207, 0.0242813,  0.110135, 0.0167875, 0.0186209, -0.0459016, 0.00583824, 0.00465495,  0.0290916, 0.0784412, -0.820519, 0.682094, 0.0308925, 0.103485,  0.0156807, -0.951232, 0.0204017, 0.811665, 0.165508,  0.00346209, -0.0863653, -0.0862366, 0.0036321, 0.156011,  1.85959, -1.06225, -1.01807, 0.0647124, 0.0207452, 0.0130816,  0.152331, -0.199505, 0.013347, 0.101707, 0.0578199, -0.702532,  0.511571, 0.0314353, 0.0533541, 0.0844481, -0.950827, -0.906468,  1.71949}}, {{{-1., 0.952494, 0.996729, 0.496308, 0.726535,  0.105968, -1., 0.457081, 0.376456, 0.28727, 0.982214,  0.412417, -1., 0.82918, 0.183038, 0.559496, 0.904913,  0.651514, -1., 0.586575, 0.919437, 0.0453144, 0.971292,  0.603285, -1., -1., 0.832683, 0.941044, 0.258817, 0.567284,  0.880188, -1., 0.944316, 0.762509, 0.840748, 0.77422,  0.487234, -1., 0.386053, 0.553478, 0.792006, 0.0748173,  0.556873, -1., 0.37044, 0.232509, 0.169905, 0.905359,  0.783866, -1., -1., 0.313072, 0.12459, 0.934066, 0.180581,  0.480389, -1., 0.183546, 0.67525, 0.613297, 0.600201,  0.23923, -1., 0.912741, 0.772548, 0.825981, 0.751996,  0.526688, -1., 0.21907, 0.0339752, 0.677179, 0.969815,  0.84863, -1., -1., 0.801466, 0.507274, 0.0644565, 0.0647643,  0.488394, -1., 0.382684, 0.13039, 0.884183, 0.00800531,  0.199138, -1., 0.455141, 0.270886, 0.407805, 0.959908,  0.5424, -1., 0.498338, 0.581824, 0.207912, 0.0157121,  0.279267, -1.},  0.547849, {1., 0.530733, 0.045897, 0.430637, 0.746382, 0.0234594,  1., 0.981441, 0.365873, 0.257988, 0.640776, 0.851051, 1., 0.48169,  0.249983, 0.441638, 0.39591, 0.210803, 1., 0.842178, 0.481731,  0.85351, 0.712465, 0.260354, 1.}, {0.273819, 0.837798, 0.433198,  0.712506, 0.743086}, {0.791901, 0.00256051, 0.966123, 0.719626,  0.81046}, {{3, 1}, {0, 3}, {0, 1}, {1, 1}, {0, 4}, {0, 0}, {2,  4}, {3, 3}}, 0.636687, 0.708135, 0.0788502, 0.95941,  0.154998}, {1.11634, -0.419276,  0.0503016, -0.354052, -0.393311, -0.849871, 2.6083,  0.326428, -1.07372, -1.01113, -0.673909, -0.547442,  2.32162, -0.651087, -0.449185, -0.961395, -1.08324, 0.231046,  2.78738, -0.97379, -1.14171, -0.634518, 0.13117, -1.0373, 2.68236,  0.376839, -0.457744, 0.0131278, 0.0427197, 0.0250571,  0.048253, -0.202244, 0.0431873, 0.0591447, 0.0516593,  0.0271701, -0.704595, 0.584456, 0.0531684, 0.0398012,  0.0407843, -1.09131, 0.0612502, 0.904718, 0.0845555,  0.114332, -1.15778, 0.0357086, 0.0440584, 0.963683, 0.335575,  0.0346345, 0.0479824, 0.0118322, -0.430024, 0.0846368, 1.09526,  0.141425, 0.0604219, -1.38174, 0.037253, 0.0695497, 0.593077,  0.0216973, -0.721577, 0.040809, 0.0463796, 0.0684797,  0.960051, -1.11572, 0.165819, 0.054514, 0.0328626,  0.0405254, -0.293721, 0.65988, -0.444313, 0.048676, -0.368882,  0.104639, 0.163882, 0.701311, 0.196758, -1.1446, 0.0826503,  0.175643, -0.623026, 1.00408, -0.668174, 0.111474,  0.170605, -1.16664, 0.135174, 0.714982, 0.145878,  0.113327, -1.06882, 0.301685, -1.09394, 1.74775}}};

  for (unsigned int i = 0; i < sizeof (data) / sizeof (data[0]); ++i)
    {
      for (unsigned int j = 0; j < 4; ++j)
        {
          for (unsigned int k = 0; k < 5; ++k)
            {
              data[i].inputs.alpha[j * 5 * 5 + k * 5 + k] = drand48 ();
            }
        }

      for (unsigned int k = 0; k < 5; ++k)
        {
          data[i].inputs.gamma[k * 5 + k] = drand48 ();
        }

      float dalpha[4 * 5 * 5];
      memset (dalpha, 0, 4 * 5 * 5 * sizeof (dalpha[0]));

      dqfunc (dalpha,
              data[i].inputs.alpha,
              5,
              data[i].inputs.logbeta,
              data[i].inputs.pz,
              data[i].inputs.ratings,
              8,
              0);

      for (unsigned int j = 0; j < 4; ++j)
        {
          for (unsigned int k = 0; k < 5; ++k)
            {
              for (unsigned int l = 0; l < 5; ++l)
                {
                  if (l == k)
                    {
                      assert (fabs (dalpha[j * 5 * 5 + k * 5 + l]) <= 1e-5 ||
                          (fprintf (stderr, "%u %u %u: %g ?= %g\n", j, k, l, dalpha[j * 5 * 5 + k * 5 + l], 0.0),
                           0));
                    }
                  else
                    {
                      assert (fabs (dalpha[j * 5 * 5 + k * 5 + l] - data[i].dalpha[j * 5 * 5 + k * 5 + l]) <= 1e-4 * (1 + fabs (dalpha[j * 5 * 5 + k * 5 + l]) + fabs (data[i].dalpha[j * 5 * 5 + k * 5 + l])) ||
                          (fprintf (stderr, "%u %u %u: %g ?= %g\n", j, k, l, dalpha[j * 5 * 5 + k * 5 + l], data[i].dalpha[j * 5 * 5 + k * 5 + l]),
                           0));
                    }
                }
            }
        }
    }
}

static void
test_dqfunc_symmetric (void)
{
  DQFuncTestDatum data[] = 
    {{{{-1., 0.458152, 0.637212, 0.5635, 0.944194, 0.615974, -1.,  0.155481, 0.70999, 0.231729, 0.35562, 0.881663, -1., 0.872192,  0.798531, 0.643114, 0.138577, 0.0802906, -1., 0.79597, 0.676991,  0.418951, 0.26983, 0.159283, -1., -1., 0.968855, 0.340101,  0.31042, 0.0042854, 0.510703, -1., 0.702889, 0.74692, 0.0600912,  0.894729, 0.547407, -1., 0.0369307, 0.828362, 0.539109, 0.665745,  0.164739, -1., 0.0298315, 0.895995, 0.527168, 0.0844484,  0.233861, -1., -1., 0.219004, 0.108217, 0.814618, 0.0745782,  0.250149, -1., 0.768116, 0.504198, 0.0702928, 0.739446,  0.0652274, -1., 0.757277, 0.0102017, 0.844718, 0.51782,  0.720347, -1., 0.181839, 0.305609, 0.852075, 0.555608,  0.152008, -1., -1., 0.409614, 0.324907, 0.471159, 0.918147,  0.19061, -1., 0.21669, 0.656541, 0.843568, 0.940461,  0.448574, -1., 0.152343, 0.773275, 0.201015, 0.383347,  0.395066, -1., 0.763074, 0.356297, 0.865527, 0.674719,  0.581235, -1.},  0.0506886, {1., 0.0134516, 0.119111, 0.429227, 0.641075, 0.688544,  1., 0.647952, 0.51108, 0.450465, 0.471854, 0.991411, 1., 0.667512,  0.510004, 0.0232798, 0.839067, 0.894237, 1., 0.308989, 0.639933,  0.444002, 0.131163, 0.952691, 1.}, {0.774406, 0.769283, 0.549928,  0.902003, 0.760955}, {0.650171, 0.120701, 0.260928, 0.0724103,  0.00221958}, {{0, 3}, {0, 2}, {1, 4}, {3, 3}, {3, 0}, {3, 2}, {0,  2}, {2, 1}}, 0.609621, 0.810464, 0.600556, 0.0108089,  0.942109}, {1.42365, 0.575389, -1.19939, -0.206607, 0.36633,  0.575389, 1.24416, -0.958095, -0.317763,  0.726017, -1.19939, -0.958095, -0.173986, -2.09834, -1.24047,  -0.206607, -0.317763, -2.09834, 0.777187, -0.326655, 0.36633,  0.726017, -1.24047, -0.326655, 1.40857, 0.413573, 0.109431,  0.175624, 0.21883, -0.542039, 0.109431, 0.45471, 0.126763,  0.144803, -0.538707, 0.175624, 0.126763, 0.305618,  0.255516, -0.479723, 0.21883, 0.144803, 0.255516,  0.455, -0.669478, -0.542039, -0.538707, -0.479723, -0.669478,  -0.429921, 0.395442, -0.590626, 0.214755, 0.136779,  0.240992, -0.590626, -0.396986, -0.468635, -0.755838, -0.552973,  0.214755, -0.468635, 0.293623, 0.129252, 0.222699,  0.136779, -0.755838, 0.129252, 0.527286, 0.253306,  0.240992, -0.552973, 0.222699, 0.253306, 0.350924,  0.52761, -0.202474, -0.84247, -1.14919, -0.421044, -0.202474,  1.33115, -0.195248, -0.305701, 0.408848, -0.84247, -0.195248,  0.298678, -0.806583, -0.430575, -1.14919, -0.305701, -0.806583,  0.596696, -0.321984, -0.421044, 0.408848, -0.430575, -0.321984,  1.51228}}, {{{-1., 0.30046, 0.577277, 0.171742, 0.0478726,  0.991471, -1., 0.937344, 0.72774, 0.91671, 0.0387799,  0.162937, -1., 0.958457, 0.366782, 0.136777, 0.401983,  0.308286, -1., 0.24608, 0.875849, 0.329572, 0.306066,  0.636459, -1., -1., 0.0653855, 0.729016, 0.295257, 0.69435,  0.764926, -1., 0.151739, 0.123516, 0.646477, 0.773454,  0.214396, -1., 0.395776, 0.729767, 0.734675, 0.0514587,  0.437319, -1., 0.362986, 0.597897, 0.649476, 0.129033,  0.116905, -1., -1., 0.722048, 0.319904, 0.822966, 0.480446,  0.656663, -1., 0.590888, 0.527709, 0.786096, 0.891737,  0.439148, -1., 0.404193, 0.139619, 0.118283, 0.224752,  0.00841708, -1., 0.409852, 0.383608, 0.173294, 0.571099,  0.0468662, -1., -1., 0.785711, 0.523818, 0.442066, 0.929961,  0.0636623, -1., 0.203914, 0.6191, 0.449514, 0.406999,  0.613026, -1., 0.0913909, 0.663418, 0.515262, 0.173878,  0.687198, -1., 0.523799, 0.396979, 0.949126, 0.678781,  0.113947, -1.},  0.0133712, {1., 0.775832, 0.107682, 0.0670807, 0.22766, 0.252014,  1., 0.665616, 0.13712, 0.163998, 0.0481005, 0.0465167, 1.,  0.687605, 0.756999, 0.435074, 0.955126, 0.0241875, 1., 0.241737,  0.261196, 0.267928, 0.500389, 0.844757, 1.}, {0.312071, 0.589147,  0.386442, 0.831386, 0.536239}, {0.481465, 0.319361, 0.603726,  0.284224,  0.815848}, {{2, 1}, {2, 1}, {0, 3}, {3, 1}, {0, 2}, {0, 2}, {0,  2}, {1, 0}}, 0.182241, 0.439728, 0.236124, 0.769332,  0.494636}, {0.596562, 0.530297, -0.645121, 0.406985, 0.577965,  0.530297, 1.38453, -1.46978, -0.0485916,  0.352552, -0.645121, -1.46978, -0.269532, -2.55108, -1.13473,  0.406985, -0.0485916, -2.55108, 0.932363, 0.262625, 0.577965,  0.352552, -1.13473, 0.262625,  1.07496, -0.155051, -0.4484, -0.327971, -0.690377, -0.460063,  -0.4484, 0.276467, 0.150166, 0.218045, 0.109264, -0.327971, 0.150166,  0.206033, 0.14835, 0.0882171, -0.690377, 0.218045, 0.14835,  0.404381, 0.177768, -0.460063, 0.109264, 0.0882171, 0.177768,  0.303173, 0.347984, -0.452656, 0.193207, 0.198375,  0.202496, -0.452656, -0.511889, -0.569814, -1.34651, -0.88366,  0.193207, -0.569814, 0.388166, 0.312936, 0.298701,  0.198375, -1.34651, 0.312936, 0.9105, 0.352287, 0.202496, -0.88366,  0.298701, 0.352287, 0.559879, 0.180678, -0.234785, 0.0798537,  0.141079,  0.0689701, -0.234785, -0.279963, -0.240936, -0.698227, -0.399822,  0.0798537, -0.240936, 0.193424, 0.205501, 0.092722,  0.141079, -0.698227, 0.205501, 0.427702, 0.156824,  0.0689701, -0.399822, 0.092722, 0.156824,  0.30698}}, {{{-1., 0.682729, 0.80105, 0.814206, 0.470448,  0.440992, -1., 0.539853, 0.546278, 0.97006, 0.596235,  0.227783, -1., 0.957131, 0.583618, 0.764848, 0.691544,  0.475666, -1., 0.264256, 0.161123, 0.407319, 0.659818,  0.082015, -1., -1., 0.721395, 0.171196, 0.890487, 0.587379,  0.0386663, -1., 0.370146, 0.0762807, 0.116931, 0.597674,  0.830293, -1., 0.530003, 0.146871, 0.00143978, 0.60251,  0.572871, -1., 0.563254, 0.236591, 0.910966, 0.097205,  0.298997, -1., -1., 0.075469, 0.503647, 0.437387, 0.216982,  0.354074, -1., 0.332451, 0.5469, 0.629603, 0.315408,  0.962305, -1., 0.47062, 0.512672, 0.717733, 0.132013,  0.940617, -1., 0.365801, 0.716294, 0.529503, 0.367746,  0.802547, -1., -1., 0.479702, 0.618536, 0.270541, 0.50355,  0.404233, -1., 0.11489, 0.833154, 0.286568, 0.0501592,  0.782439, -1., 0.286253, 0.656965, 0.734751, 0.820134,  0.815634, -1., 0.144293, 0.0170181, 0.688121, 0.875017,  0.778492, -1.},  0.300724, {1., 0.158619, 0.507271, 0.975944, 0.821022, 0.540082,  1., 0.23673, 0.472394, 0.416789, 0.425192, 0.403577, 1., 0.185826,  0.36663, 0.642753, 0.117323, 0.528862, 1., 0.631879, 0.82262,  0.30169, 0.384569, 0.61486, 1.}, {0.134499, 0.426673, 0.606077,  0.314136, 0.97588}, {0.919402, 0.630133, 0.493114, 0.435798,  0.682672}, {{0, 0}, {3, 3}, {1, 4}, {3, 4}, {1, 0}, {1, 2}, {1,  2}, {1, 2}}, 0.157738, 0.0763246, 0.0106054, 0.279095,  0.971912}, {-0.0532136, -0.521378, -0.756157, -0.388246, -1.18054,  -0.521378, 0.405431, 0.123618, 0.0861422, 0.0894743, -0.756157,  0.123618, 0.584151, 0.0621579, 0.171847, -0.388246, 0.0861422,  0.0621579, 0.290166, 0.211255, -1.18054, 0.0894743, 0.171847,  0.211255, 0.875294,  0.424646, -0.352328, -0.744676, -0.271316, -0.967017, -0.352328,  1.68558, -1.08635, 0.711845,  0.668479, -0.744676, -1.08635, -0.0504957, -0.796227, -3.42503,  -0.271316, 0.711845, -0.796227, 1.36089, 0.217556, -0.967017,  0.668479, -3.42503, 0.217556, 2.62444, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.233118, 0.128163,  0.139946, -0.0475025, 0.0615178, 0.128163, 0.712788,  0.382717, -0.473295, -0.165966, 0.139946, 0.382717,  1.01281, -0.550154, -0.537882, -0.0475025, -0.473295, -0.550154,  0.0891126, -1.28772, 0.0615178, -0.165966, -0.537882, -1.28772,  0.302346}}, {{{-1., 0.709695, 0.367852, 0.161772, 0.44305,  0.0778161, -1., 0.545232, 0.860082, 0.0584816, 0.462956,  0.410734, -1., 0.433409, 0.452405, 0.14882, 0.434854,  0.514006, -1., 0.822272, 0.655706, 0.999056, 0.831334,  0.664534, -1., -1., 0.579381, 0.988451, 0.552239, 0.692622,  0.869687, -1., 0.620599, 0.390468, 0.249571, 0.791871,  0.0753666, -1., 0.530386, 0.19109, 0.328915, 0.664633,  0.0969776, -1., 0.738685, 0.180095, 0.229779, 0.582971,  0.916413, -1., -1., 0.52439, 0.230723, 0.751637, 0.25188,  0.945008, -1., 0.242273, 0.199397, 0.559258, 0.0753216,  0.621674, -1., 0.80893, 0.309687, 0.283451, 0.546307,  0.278543, -1., 0.118597, 0.954536, 0.881674, 0.181566,  0.379912, -1., -1., 0.774441, 0.651895, 0.598594, 0.463499,  0.250051, -1., 0.421172, 0.846958, 0.211619, 0.305043,  0.178899, -1., 0.64756, 0.652361, 0.229721, 0.557225,  0.83863, -1., 0.342674, 0.94627, 0.0109177, 0.560087,  0.224078, -1.},  0.991734, {1., 0.129244, 0.378521, 0.844166, 0.217293, 0.477349,  1., 0.779927, 0.380667, 0.967242, 0.0561771, 0.932969, 1.,  0.169048, 0.6622, 0.877278, 0.285409, 0.516687, 1., 0.432479,  0.320053, 0.446779, 0.174013, 0.486209, 1.}, {0.309136, 0.886692,  0.949935, 0.494475, 0.179892}, {0.50817, 0.10577, 0.277181,  0.702543,  0.728244}, {{3, 1}, {1, 1}, {1, 3}, {2, 1}, {0, 1}, {1, 4}, {3,  2}, {1, 0}}, 0.725102, 0.309939, 0.646366, 0.795275,  0.556054}, {0.758284, -0.804, 0.0782584, 0.0870054,  0.0244657, -0.804, -0.196884, -2.49015, -1.31028, -0.33325,  0.0782584, -2.49015, 2.36804, 0.0755998, 0.0559384,  0.0870054, -1.31028, 0.0755998, 1.23591, 0.0123135,  0.0244657, -0.33325, 0.0559384, 0.0123135, 0.438746,  2.35816, -3.05392, -2.50113, -2.04156, -1.2666, -3.05392,  6.42384, -2.3285, -3.39789, -2.51087, -2.50113, -2.3285,  9.53948, -2.32593, -2.10491, -2.04156, -3.39789, -2.32593,  3.67777, -1.75554, -1.2666, -2.51087, -2.10491, -1.75554, 1.28761,  0.76057, -0.785436, 0.11127, 0.0174969,  0.0407461, -0.785436, -0.228895, -2.40388, -1.20029, -0.446248,  0.11127, -2.40388, 2.31079, 0.0268087, 0.0802594,  0.0174969, -1.20029, 0.0268087, 1.20644, 0.0802169,  0.0407461, -0.446248, 0.0802594, 0.0802169, 0.430146,  1.58323, -0.782958, -0.758556, 0.0551109, 0.0477428, -0.782958,  2.05661, -4.74987, -1.28514, -0.281588, -0.758556, -4.74987,  2.28601, -1.24633, -0.418338, 0.0551109, -1.28514, -1.24633,  2.51785, 0.0911646, 0.0477428, -0.281588, -0.418338, 0.0911646,  0.885065}}, {{{-1., 0.647739, 0.769088, 0.509866, 0.0393667,  0.215261, -1., 0.449035, 0.063087, 0.865354, 0.729052,  0.139899, -1., 0.176395, 0.915418, 0.234578, 0.960007,  0.668225, -1., 0.809649, 0.957396, 0.257464, 0.939981,  0.0845464, -1., -1., 0.647458, 0.611098, 0.144707, 0.528492,  0.999718, -1., 0.84201, 0.634841, 0.489126, 0.784458,  0.392975, -1., 0.571754, 0.623772, 0.0554054, 0.253076,  0.395359, -1., 0.708354, 0.820828, 0.293069, 0.727134,  0.898705, -1., -1., 0.863431, 0.0356046, 0.787152, 0.814158,  0.215974, -1., 0.424507, 0.642445, 0.285666, 0.216256,  0.582497, -1., 0.00760437, 0.79654, 0.431798, 0.189522,  0.43585, -1., 0.172768, 0.376393, 0.936446, 0.0404917,  0.464415, -1., -1., 0.555565, 0.643378, 0.313358, 0.56571,  0.692133, -1., 0.607773, 0.526206, 0.751552, 0.476159,  0.183266, -1., 0.883761, 0.465886, 0.259904, 0.600769,  0.876156, -1., 0.669345, 0.828106, 0.411247, 0.440306,  0.496577, -1.},  0.451713, {1., 0.474801, 0.399814, 0.032162, 0.896148, 0.831423,  1., 0.0864559, 0.466452, 0.204015, 0.22365, 0.56025, 1., 0.7149,  0.727856, 0.0403835, 0.676489, 0.249014, 1., 0.467952, 0.439614,  0.800333, 0.579669, 0.639846, 1.}, {0.0283673, 0.360027,  0.0830916, 0.188133, 0.553567}, {0.960213, 0.0509296, 0.291984,  0.722144,  0.873757}, {{0, 3}, {0, 2}, {2, 3}, {0, 3}, {0, 1}, {3, 0}, {1,  1}, {3, 1}}, 0.584478, 0.0879692, 0.498494, 0.313507,  0.869578}, {0.125018, 0.0845728, -0.0131682, -0.00380477, 0.525502,  0.0845728,  1.02835, -0.493445, -0.978122, -0.647698, -0.0131682, -0.493445,  0.250147, -0.372277, -0.724343, -0.00380477, -0.978122, -0.372277,  0.198456, -1.54391, 0.525502, -0.647698, -0.724343, -1.54391,  2.56472, 0.031586, -0.00958086, 0.0105188, 0.0403051,  0.0619587, -0.00958086, -0.131715, -0.100945, -0.246054, -0.764967,  0.0105188, -0.100945, 0.100599, 0.026448, 0.0587287,  0.0403051, -0.246054, 0.026448, 0.21184, 0.0590191,  0.0619587, -0.764967, 0.0587287, 0.0590191, 0.652259, 0.0325708,  0.0238665, 0.022762, -0.0307078, 0.0375992, 0.0238665, 0.413256,  0.052968, -0.519371, 0.13676, 0.022762, 0.052968,  0.0832482, -0.0729724,  0.041668, -0.0307078, -0.519371, -0.0729724, -0.0985063, -0.740607,  0.0375992, 0.13676, 0.041668, -0.740607, 0.617466,  0.0202585, -0.530216, -0.110529, -0.231384, -0.751669, -0.530216,  0.290351, -0.0460934, -0.177687, -0.731053, -0.110529, -0.0460934,  0.199681, 0.0331849, 0.151499, -0.231384, -0.177687, 0.0331849,  0.44033, 0.127527, -0.751669, -0.731053, 0.151499, 0.127527,  1.3158}}, {{{-1., 0.360113, 0.45811, 0.637018, 0.620564,  0.892162, -1., 0.0184961, 0.836685, 0.0408952, 0.252315,  0.990129, -1., 0.476658, 0.957804, 0.0641826, 0.436562,  0.516445, -1., 0.906874, 0.772198, 0.714419, 0.642688,  0.322396, -1., -1., 0.684229, 0.215925, 0.329181, 0.452818,  0.324116, -1., 0.757814, 0.692163, 0.832255, 0.431954,  0.739318, -1., 0.855478, 0.791359, 0.179639, 0.749189,  0.37882, -1., 0.833556, 0.115456, 0.312627, 0.862376,  0.926682, -1., -1., 0.343258, 0.598209, 0.219688, 0.604286,  0.659029, -1., 0.382284, 0.890507, 0.151467, 0.334913,  0.62447, -1., 0.198344, 0.319213, 0.902959, 0.885152,  0.342866, -1., 0.527853, 0.72332, 0.135962, 0.964046,  0.694298, -1., -1., 0.607864, 0.823335, 0.10167, 0.767616,  0.264606, -1., 0.225126, 0.881983, 0.16333, 0.605578,  0.842842, -1., 0.991475, 0.0118629, 0.270665, 0.218373,  0.793131, -1., 0.69265, 0.367706, 0.333221, 0.450265,  0.164797, -1.},  0.644385, {1., 0.197259, 0.486219, 0.470499, 0.0365213, 0.373923,  1., 0.384549, 0.702883, 0.771915, 0.148797, 0.502566, 1.,  0.539553, 0.166337, 0.305955, 0.511091, 0.52769, 1., 0.895673,  0.087582, 0.71796, 0.83504, 0.527967, 1.}, {0.754361, 0.267695,  0.670243, 0.883582, 0.557103}, {0.781475, 0.199744, 0.847061,  0.183179,  0.396927}, {{2, 0}, {0, 1}, {2, 3}, {3, 1}, {0, 2}, {2, 3}, {2,  4}, {1, 3}}, 0.496861, 0.0751454, 0.0343821, 0.89436,  0.957308}, {2.34209, -1.20622, -1.16813, 0.231862,  0.185419, -1.20622,  0.225574, -1.39647, -1.57314, -0.723047, -1.16813, -1.39647,  0.702759, -1.39014, -0.972348, 0.231862, -1.57314, -1.39014,  2.8994, 0.122219, 0.185419, -0.723047, -0.972348, 0.122219,  1.72017, 1.12134, 0.063329, 0.215944, -1.23425, 0.128091, 0.063329,  0.444986, 0.0531548, -0.435333, 0.0415496, 0.215944, 0.0531548,  1.06751, -1.20389,  0.0654394, -1.23425, -0.435333, -1.20389, -0.255452, -0.989838,  0.128091, 0.0415496, 0.0654394, -0.989838, 0.917406,  3.08855, -0.037028, -0.874404, -3.59913, -2.1306, -0.037028,  1.58343, 0.395535, -0.833234, 0.0325786, -0.874404, 0.395535,  3.9206, -1.61758, -0.693181, -3.59913, -0.833234, -1.61758,  1.88637, -3.34073, -2.1306, 0.0325786, -0.693181, -3.34073,  2.21881, 1.16357, -1.36389, 0.0666521, 0.312917,  0.0676811, -1.36389, -0.111697, -1.14259, -1.63351, -0.930667,  0.0666521, -1.14259, 0.985096, 0.053437, 0.259566,  0.312917, -1.63351, 0.053437, 1.38787, 0.0869942,  0.0676811, -0.930667, 0.259566, 0.0869942,  0.798564}}, {{{-1., 0.908808, 0.728428, 0.38327, 0.429618,  0.013135, -1., 0.640846, 0.66531, 0.594578, 0.485168,  0.886484, -1., 0.397616, 0.924335, 0.601586, 0.329382,  0.61614, -1., 0.724591, 0.754525, 0.146203, 0.219213,  0.22773, -1., -1., 0.67938, 0.111821, 0.324853, 0.270422,  0.770572, -1., 0.383393, 0.941583, 0.840803, 0.757437,  0.742547, -1., 0.276273, 0.246225, 0.272269, 0.856063,  0.878658, -1., 0.32189, 0.670683, 0.526681, 0.262518,  0.5973, -1., -1., 0.916158, 0.380479, 0.0433042, 0.36957,  0.236778, -1., 0.268658, 0.718451, 0.0991483, 0.466206,  0.885265, -1., 0.776868, 0.258345, 0.708769, 0.142718,  0.500595, -1., 0.0121196, 0.4365, 0.286655, 0.621938,  0.690229, -1., -1., 0.765817, 0.759973, 0.35942, 0.0929298,  0.849659, -1., 0.379495, 0.316116, 0.72336, 0.612881,  0.110837, -1., 0.597665, 0.624212, 0.146675, 0.225572,  0.820796, -1., 0.365867, 0.437905, 0.0828539, 0.320201,  0.353747, -1.},  0.00140551, {1., 0.796199, 0.698263, 0.663518, 0.235589, 0.0362261,  1., 0.338843, 0.570588, 0.38593, 0.656731, 0.0227274, 1.,  0.847228, 0.77305, 0.545895, 0.425063, 0.223016, 1., 0.626375,  0.320323, 0.604267, 0.85715, 0.18847, 1.}, {0.237469, 0.284065,  0.503403, 0.187064, 0.44127}, {0.585802, 0.839885, 0.951475,  0.405044,  0.246959}, {{1, 3}, {1, 3}, {0, 0}, {0, 3}, {1, 0}, {3, 1}, {1,  0}, {3, 1}}, 0.269297, 0.565545, 0.748312, 0.224231,  0.422069}, {0.0243572, -0.197146, -0.356363, -0.309202, -0.259612,  -0.197146, 0.328395, 0.174099, -0.184564, 0.167938, -0.356363,  0.174099, 0.57195, -0.313411,  0.156164, -0.309202, -0.184564, -0.313411,  0.0137244, -0.317097, -0.259612, 0.167938, 0.156164, -0.317097,  0.500768, -0.0138647, -0.361193, -0.547709, -0.625941, -0.505719,  -0.361193, 0.654825, 0.399176, -0.42034, 0.244112, -0.547709,  0.399176, 0.940354, -0.639389,  0.524737, -0.625941, -0.42034, -0.639389,  0.00898815, -0.545496, -0.505719, 0.244112, 0.524737, -0.545496,  0.887459, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0.24601, -0.381653, 0.137224, 0.111543,  0.232961, -0.381653, -0.264291, -0.792629, -0.242474, -0.749433,  0.137224, -0.792629, 0.55355, 0.149964, 0.197312,  0.111543, -0.242474, 0.149964, 0.189164, 0.162771,  0.232961, -0.749433, 0.197312, 0.162771,  0.449982}}, {{{-1., 0.792495, 0.202418, 0.799168, 0.199052,  0.16612, -1., 0.882094, 0.194902, 0.341903, 0.977651,  0.644625, -1., 0.910836, 0.8385, 0.790587, 0.203355,  0.325035, -1., 0.998615, 0.839112, 0.798311, 0.0780759,  0.729319, -1., -1., 0.273567, 0.0499989, 0.853845, 0.30725,  0.481071, -1., 0.847581, 0.0546763, 0.108197, 0.314951,  0.965487, -1., 0.859774, 0.766295, 0.3373, 0.320862,  0.948938, -1., 0.927795, 0.546713, 0.117507, 0.623903,  0.929179, -1., -1., 0.707602, 0.319196, 0.545828, 0.199861,  0.434035, -1., 0.269197, 0.691983, 0.892611, 0.952964,  0.421615, -1., 0.637307, 0.784414, 0.638013, 0.456128,  0.777532, -1., 0.0181189, 0.300712, 0.135267, 0.828594,  0.0903242, -1., -1., 0.753999, 0.0177598, 0.204691, 0.161145,  0.046397, -1., 0.698564, 0.658863, 0.961284, 0.612362,  0.429368, -1., 0.96688, 0.0686727, 0.659398, 0.00775229,  0.329574, -1., 0.284259, 0.0213856, 0.551624, 0.552042,  0.26614, -1.},  0.720673, {1., 0.416357, 0.723448, 0.175816, 0.966675, 0.398597,  1., 0.518757, 0.0146712, 0.920278, 0.700033, 0.859894, 1.,  0.0533874, 0.307916, 0.270665, 0.893014, 0.984715, 1., 0.648517,  0.262913, 0.56344, 0.700456, 0.627132, 1.}, {0.711289, 0.0113986,  0.434316, 0.906458, 0.294932}, {0.287951, 0.2585, 0.939784,  0.896335,  0.769194}, {{2, 2}, {1, 3}, {1, 2}, {2, 2}, {2, 2}, {3, 3}, {1,  4}, {3, 3}}, 0.243828, 0.0195064, 0.196302, 0.9093,  0.190441}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 3.43099,  0.254138, -0.805272, -1.28133, -1.12699, 0.254138, 0.0535748,  0.0283689, 0.525817, 0.135328, -0.805272, 0.0283689,  1.36521, -2.60326, -1.39978, -1.28133, 0.525817, -2.60326,  2.88486, -2.35118, -1.12699, 0.135328, -1.39978, -2.35118, 0.88954,  3.58748, 0.109018, -4.00041, 0.338842, 0.42754, 0.109018,  0.0608787, 0.0984429, 0.142085, 0.0308721, -4.00041,  0.0984429, -0.446505, -5.35658, -1.72501, 0.338842,  0.142085, -5.35658, 4.54381, 0.739137, 0.42754,  0.0308721, -1.72501, 0.739137, 1.45041, 2.20475, 0.061036,  0.443884, -2.47962, 0.288851, 0.061036, 0.0422842, 0.0436739,  0.0566132, 0.0173973, 0.443884, 0.0436739, 1.39238, -1.70714,  0.259046, -2.47962, 0.0566132, -1.70714, -0.636467, -0.925192,  0.288851, 0.0173973, 0.259046, -0.925192,  0.938501}}, {{{-1., 0.711591, 0.925636, 0.0162862, 0.205726,  0.0630733, -1., 0.662723, 0.452846, 0.505271, 0.435942,  0.951434, -1., 0.441447, 0.0709551, 0.529483, 0.656502,  0.153496, -1., 0.812456, 0.589699, 0.760167, 0.384302,  0.568627, -1., -1., 0.570193, 0.563865, 0.475002, 0.378186,  0.858602, -1., 0.638229, 0.458716, 0.17246, 0.795529,  0.975506, -1., 0.00587029, 0.667189, 0.359587, 0.0240724,  0.564423, -1., 0.596234, 0.830104, 0.367571, 0.410926,  0.783779, -1., -1., 0.240405, 0.607404, 0.026624, 0.215152,  0.670212, -1., 0.0435385, 0.551622, 0.836965, 0.81161,  0.405309, -1., 0.0929053, 0.664505, 0.0160817, 0.429803,  0.087035, -1., 0.997316, 0.656495, 0.405731, 0.522612,  0.401081, -1., -1., 0.826391, 0.0381599, 0.111686, 0.617303,  0.585986, -1., 0.430756, 0.0850617, 0.402151, 0.915774,  0.387218, -1., 0.53344, 0.565186, 0.104164, 0.981908,  0.440535, -1., 0.90068, 0.0880818, 0.552105, 0.3535,  0.903365, -1.},  0.431587, {1., 0.146374, 0.830888, 0.502283, 0.605196, 0.108214,  1., 0.719202, 0.884981, 0.0192103, 0.677458, 0.63414, 1., 0.48283,  0.103437, 0.290241, 0.1007, 0.917644, 1., 0.999273, 0.308333,  0.660165, 0.0169638, 0.911191, 1.}, {0.756228, 0.306666, 0.113599,  0.479604, 0.609853}, {0.475778, 0.611316, 0.874408, 0.501639,  0.756576}, {{1, 1}, {3, 2}, {3, 2}, {0, 4}, {3, 4}, {3, 2}, {1,  4}, {3, 3}}, 0.726335, 0.855197, 0.824181, 0.122436,  0.243505}, {0.782176, 0.0810746, 0.0466415, 0.267509, -0.944913,  0.0810746, 0.348652, 0.0364059, 0.0902962, -0.376509, 0.0466415,  0.0364059, 0.122332, 0.0672996, -0.0317088, 0.267509, 0.0902962,  0.0672996,  0.496943, -0.669731, -0.944913, -0.376509, -0.0317088, -0.669731,  -0.316468, 1.66084, -0.95786, 0.171057, 0.272533, -0.809893, -0.95786,  0.183777, -0.103018, -0.565334, -1.08983, 0.171057, -0.103018,  0.239673, 0.259181, -0.0568509, 0.272533, -0.565334, 0.259181,  0.979909, -0.543373, -0.809893, -1.08983, -0.0568509, -0.543373,  0.359189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 3.81571,  0.325463, -2.60338, -0.0357822, -0.557989, 0.325463,  1.60153, -1.17504, 0.2871, 0.116711, -2.60338, -1.17504,  0.0595365, -2.1055, -2.6251, -0.0357822, 0.2871, -2.1055,  1.69611, -1.35948, -0.557989, 0.116711, -2.6251, -1.35948,  2.56011}}, {{{-1., 0.751761, 0.53394, 0.0217359, 0.325861,  0.752488, -1., 0.225607, 0.36157, 0.308897, 0.841297,  0.46938, -1., 0.0549048, 0.195298, 0.361693, 0.859527,  0.579127, -1., 0.583982, 0.487285, 0.357888, 0.82255,  0.857647, -1., -1., 0.632088, 0.533707, 0.700114, 0.614142,  0.880327, -1., 0.999767, 0.678378, 0.288281, 0.127839,  0.77416, -1., 0.316808, 0.979384, 0.286542, 0.30478,  0.261903, -1., 0.784086, 0.924849, 0.445253, 0.682777,  0.200104, -1., -1., 0.437564, 0.0873658, 0.860226, 0.342457,  0.805476, -1., 0.553659, 0.160112, 0.728315, 0.92515,  0.553891, -1., 0.481733, 0.440034, 0.797311, 0.779732,  0.164925, -1., 0.46065, 0.510769, 0.474952, 0.903022,  0.676564, -1., -1., 0.585919, 0.0296981, 0.220246, 0.47646,  0.148355, -1., 0.942332, 0.360019, 0.134003, 0.342878,  0.388674, -1., 0.199908, 0.405688, 0.417729, 0.834782,  0.718174, -1., 0.965654, 0.620418, 0.0550505, 0.553249,  0.505004, -1.},  0.10965, {1., 0.580099, 0.650227, 0.828441, 0.52373, 0.550401, 1.,  0.429982, 0.351981, 0.375376, 0.608069, 0.0699622, 1., 0.217978,  0.032497, 0.219395, 0.870054, 0.81229, 1., 0.614768, 0.384613,  0.15188, 0.846636, 0.99435, 1.}, {0.329562, 0.598631, 0.341632,  0.8847, 0.749463}, {0.948404, 0.513191, 0.36097, 0.199063,  0.518422}, {{3, 2}, {0, 2}, {0, 1}, {1, 1}, {0, 0}, {3, 4}, {1,  3}, {3, 4}}, 0.16121, 0.985594, 0.590994, 0.44846,  0.943232}, {0.222328, -0.798592, -0.539538, -0.329115, -0.400242,  -0.798592,  0.416854, -0.627755, -0.428533, -0.277071, -0.539538, -0.627755,  0.188648, -0.359256, -0.337173, -0.329115, -0.428533, -0.359256,  1.46797, 0.476842, -0.400242, -0.277071, -0.337173, 0.476842,  1.32463, 0.443738, -0.165733, 0.164731, -0.123886,  0.240726, -0.165733, 0.136638, -0.244544, -1.34991, -0.404308,  0.164731, -0.244544, 0.46837, -0.00151761,  0.162852, -0.123886, -1.34991, -0.00151761, 0.194854, -0.536331,  0.240726, -0.404308, 0.162852, -0.536331, 1.01432, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0.569843, 0.288251, 0.00344533, 0.55642, -0.356638, 0.288251,  1.12194, -0.470737, 0.5971, -0.625046, 0.00344533, -0.470737,  0.220115, -0.409778, -1.1822, 0.55642, 0.5971, -0.409778,  1.60167, -1.63988, -0.356638, -0.625046, -1.1822, -1.63988,  -0.274508}}};

  for (unsigned int i = 0; i < sizeof (data) / sizeof (data[0]); ++i)
    {
      for (unsigned int j = 0; j < 4; ++j)
        {
          for (unsigned int k = 0; k < 5; ++k)
            {
              data[i].inputs.alpha[j * 5 * 5 + k * 5 + k] = drand48 ();
            }
        }

      for (unsigned int k = 0; k < 5; ++k)
        {
          data[i].inputs.gamma[k * 5 + k] = drand48 ();
        }

      float dalpha[4 * 5 * 5];
      memset (dalpha, 0, 4 * 5 * 5 * sizeof (dalpha[0]));

      dqfunc (dalpha,
              data[i].inputs.alpha,
              5,
              data[i].inputs.logbeta,
              data[i].inputs.pz,
              data[i].inputs.ratings,
              8,
              1);

      for (unsigned int j = 0; j < 4; ++j)
        {
          for (unsigned int k = 0; k < 5; ++k)
            {
              for (unsigned int l = 0; l < 5; ++l)
                {
                  if (l <= k)
                    {
                      assert (fabs (dalpha[j * 5 * 5 + k * 5 + l]) <= 1e-5 ||
                          (fprintf (stderr, "%u %u %u: %g ?= %g\n", j, k, l, dalpha[j * 5 * 5 + k * 5 + l], 0.0),
                           0));
                    }
                  else
                    {
                      assert (fabs (dalpha[j * 5 * 5 + k * 5 + l] - data[i].dalpha[j * 5 * 5 + k * 5 + l]) <= 1e-4 * (1 + fabs (dalpha[j * 5 * 5 + k * 5 + l]) + fabs (data[i].dalpha[j * 5 * 5 + k * 5 + l])) ||
                          (fprintf (stderr, "%u %u %u: %g ?= %g\n", j, k, l, dalpha[j * 5 * 5 + k * 5 + l], data[i].dalpha[j * 5 * 5 + k * 5 + l]),
                           0));
                    }
                }
            }
        }
    }
}

int 
main (void) 
{
  srand48 (69);

  test_logprating ();
  test_normaldistribution ();
  test_qfunc ();
  test_qfunc_symmetric ();
  test_dqfunc ();
  test_dqfunc_symmetric ();

  return 0;
}
